依图科技软件开发工程师 第一题为什么这样输出结果不对呢
package Exam;
import java.util.*;
public class exam {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt(); //N个新人
int M = in.nextInt(); //每个人说M个喜好
int K = in.nextInt(); //相同爱好数达到K,成为好朋友
int maxFriend = 0;
ArrayList<ArrayList<String>> every = new ArrayList<>();
for(int i = 0; i < N; i ++){
ArrayList<String> list = new ArrayList<String>();
for(int j = 0; j < M; j ++){
list.add(in.next());
}
every.add(list);
}
for(int i = 0; i < N; i ++) {
int result = 0;//第I个人拥有的好朋友数
for(int j = 0; j < N && j != i; j ++) {
int friend = 0;//第i个人和第j个人相同的爱好数
for(int k = 0; k < M; k ++) {
for(int w = 0; w < M; w ++) {
if(every.get(i).get(k).equals(every.get(j).get(w))) {
friend ++;
//k ++;
break;
}
}
}
if(friend == K) result ++;
}
if(result > maxFriend) maxFriend = result;
}
System.out.println(maxFriend);
}
}
#依图科技##笔试题目##秋招#
import java.util.*;
public class exam {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt(); //N个新人
int M = in.nextInt(); //每个人说M个喜好
int K = in.nextInt(); //相同爱好数达到K,成为好朋友
int maxFriend = 0;
ArrayList<ArrayList<String>> every = new ArrayList<>();
for(int i = 0; i < N; i ++){
ArrayList<String> list = new ArrayList<String>();
for(int j = 0; j < M; j ++){
list.add(in.next());
}
every.add(list);
}
for(int i = 0; i < N; i ++) {
int result = 0;//第I个人拥有的好朋友数
for(int j = 0; j < N && j != i; j ++) {
int friend = 0;//第i个人和第j个人相同的爱好数
for(int k = 0; k < M; k ++) {
for(int w = 0; w < M; w ++) {
if(every.get(i).get(k).equals(every.get(j).get(w))) {
friend ++;
//k ++;
break;
}
}
}
if(friend == K) result ++;
}
if(result > maxFriend) maxFriend = result;
}
System.out.println(maxFriend);
}
}
#依图科技##笔试题目##秋招#