题目
样例输入
7
13 960
12 950
12 950
11 1310
11 1310
11 1310
0 0
样例输出
4
运行代码
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n=scan.nextInt();
int [][]team=new int [n][2];//定义一个二维数组
for(int i=0;i<n;i++){
team[i][0]=scan.nextInt();//输入通过题数
team[i][1]=scan.nextInt();//输入罚时
}
int teamcount=0;//定义队伍种类
for(int i=0;i<n;i++){
boolean category=true;
for(int j=0;j<i;j++){
if(team[i][0]==team[j][0] && team[i][1]==team[j][1]){
category=false;
break;
}
}
if(category){
teamcount++;
}
}
System.out.println(teamcount);
scan.close();
}
}
小结
多维数组
定义:int [ ][ ]a=new int[3][4];
用表格的方式更好理解多维数组,数组里的3对应3行,4对应4列。
| column1 | column2 | column3 | columm4 |
row1 | a[0][0] | a[0][1] | a[0][2] | a[0][3] |
row2 | a[1][0] | a[1][1] | a[1][2] | a[1][3] |
row3 | a[2][0] | a[2][1] | a[2][2] | a[2][3] |
初始化:java中多维数组的每一行可以具有不同的长度
| column1 | column2 | column3 | column4 |
row1 | 1 | 2 | 3 | |
row2 | 4 | 5 | 6 | 7 |
row3 | 8 | | | |
int [ ][ ]a={
{1,2,3},
{4,5,6,7},
{8},
};