1072 开学寄语 (20分)
原题链接:传送门
一、题目:
二、解析:
AC代码:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* 1072 开学寄语 (20分)
*
* @author: ChangSheng
* @date: 2020年1月3日 下午9:13:38
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String[] NM = in.readLine().split(" ");
int N = Integer.valueOf(NM[0]);
int M = Integer.valueOf(NM[1]);
String[] items = in.readLine().split(" ");
int studentCount = 0, itemsCount = 0;
for (int i = 0; i < N; i++) {
String[] student = in.readLine().split(" ");
StringBuilder sb = new StringBuilder();
boolean flag = false;
for (int j = 2; j < student.length; j++) { // 遍历学生的所有物品编号
for (int j1 = 0; j1 < items.length; j1++) {
if (student[j].equals(items[j1])) {
sb.append(student[j]+" ");
itemsCount++; // 被缴物品总数
flag = true; // 该学生存在问题
}
}
}
if (flag) studentCount++;
if (sb.length() > 0) System.out.println(student[0]+": "+sb.toString().trim());
}
System.out.print(studentCount+" "+itemsCount);
}
}