本题要注意的是如果有符合条件的日期,输出最早的。不作处理的话会输出最晚的
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while (true)
{
int n = sc.nextInt();
int q = sc.nextInt();
if (n == 0 && q == 0)
break;
int[] result = new int[100];
for (int i = 0; i < n; i++)
{
int days = sc.nextInt();
for (int j = 0; j < days; j++)
{
int day = sc.nextInt();
result[day]++;
}
}
int max = q;
int day = 0;
for (int i = 0; i < result.length; i++)
{
if (result[i] >= max)
{
if (max == result[i] && day != 0) // key point
continue;
max = result[i];
day = i;
}
}
System.out.println(day);
}
}
}