import java.util.Scanner;
import java.util.Set;
public class test8 {
private static int one=0;
private static int two=0;
private static int three=0;
private static int four=0;
private static int five=0;
private static int six=0;
private static int seven=0;
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int N=scanner.nextInt();//读取第一行数字
Set<String> set = new HashSet<>();//设置一个set类,里面是无序不能重复的数字,可以根据这个特性来判断中了几个数字。
try {
for(int i=0;i<7;i++){
set.add(scanner.next().toString());
}
int[] list=new int[7];
int[] flag=new int[N];
while(N!=0&&scanner.hasNext()){
Set<String> setTemp=new HashSet<>(set);
for(int j=0;j<7;j++){
list[j]=scanner.nextInt();
setTemp.add(String.valueOf(list[j]));
}
flag[N-1] =14-(int) setTemp.size();
is_get(flag[N-1]);
N--;
}
scanner.close();
System.out.print("["+seven+" "+six+" "+five+" "+four+" "+three+" "+two+" "+ one +"]");
}
catch (Exception e) {
// TODO: handle exception
System.out.println(e);
}
}
private static void is_get(int i) {
// TODO Auto-generated method stub
switch(i) {
case 1:
one++;
break;
case 2:
two++;
break;
case 3:
three++;
break;
case 4:
four++;
break;
case 5:
five++;
break;
case 6:
six++;
break;
default:
seven++;
break;
}
}
}
总结:1.对象的赋值与引用要有区分。例如List<String> A=B,A如果变化,B也会跟着变化,这是对象的引用。如果想让B不变化,可以采用List<String> A=new List<String>(B)的方式。
2.局部变量与全局变量。如果想要定义全局静态变量的话,需要在static void main(String[] args)之前定义。定义方式为: private static int A。
3.scanner.nextInt()与scanner.next()与scanner.nextLine()的区别一定要注意。
nextInt(): it only reads the int value, nextInt() places the cursor in the same line after reading the input.
next(): read the input only till the space. It can't read two words separated by space. Also, next() places the cursor in the same line after reading the input.
nextLine(): reads input including space between the words (that is, it reads till the end of line \n). Once the input is read, nextLine() positions the cursor in the next line.
即:next()从遇到第一个有效字符(非空格、换行符)开始扫描,遇到第一个分隔符或结束符(空格’ ‘或者换行符 ‘\n’)时结束。 nextLine()则是扫描所有字符串(包括空格)遇到回车结束!如下图,左边是scanner.next();右边是scanner.nextLine()