Java 1072 开学寄语

题目内容:

下图是上海某校的新学期开学寄语:天将降大任于斯人也,必先删其微博,卸其 QQ,封其电脑,夺其手机,收其 ipad,断其 wifi,使其百无聊赖,然后,净面、理发、整衣,然后思过、读书、锻炼、明智、开悟、精进。而后必成大器也!

jiyu.JPG

本题要求你写个程序帮助这所学校的老师检查所有学生的物品,以助其成大器。

输入格式:

输入第一行给出两个正整数 N(≤ 1000)和 M(≤ 6),分别是学生人数和需要被查缴的物品种类数。第二行给出 M 个需要被查缴的物品编号,其中编号为 4 位数字。随后 N 行,每行给出一位学生的姓名缩写(由 1-4 个大写英文字母组成)、个人物品数量 K(0 ≤ K ≤ 10)、以及 K 个物品的编号。

输出格式:

顺次检查每个学生携带的物品,如果有需要被查缴的物品存在,则按以下格式输出该生的信息和其需要被查缴的物品的信息(注意行末不得有多余空格):

姓名缩写: 物品编号1 物品编号2 ……

最后一行输出存在问题的学生的总人数和被查缴物品的总数。

输入样例:

4 2
2333 6666
CYLL 3 1234 2345 3456
U 4 9966 6666 8888 6666
GG 2 2333 7777
JJ 3 0012 6666 2333

结尾无空行

输出样例:

U: 6666 6666
GG: 2333
JJ: 6666 2333
3 5

结尾无空行

Java代码实现(AC):

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
		int[] NM = stii(bf.readLine());
		ArrayList<String> wj = new ArrayList<String>(Arrays.asList(bf.readLine().split(" ")));
		int counts = 0;
		int countw = 0;
		for (int i = 0; i < NM[0]; i++) {
			boolean hasWJ = false;
			ArrayList<String> swp = new ArrayList<String>(Arrays.asList(bf.readLine().split(" ")));
			String name = swp.remove(0);
			for (int j = 0; j < swp.size(); j++) {
				if (wj.contains(swp.get(j))) {
					countw++;
					hasWJ = true;
				} else {
					swp.remove(j);
					j--;
				}
			}
			if (hasWJ) {
				counts++;
				out.print(name + ":");
				for (String tem : swp) {
					out.print(" " + tem);
				}
				out.println();
			}
		}
		out.print(counts + " " + countw);
		out.flush();
	}

	static int sti(String a) {
		return Integer.parseInt(a);
	}

	static int[] stii(String a) {
		String[] ra = a.split(" ");
		int[] r = new int[ra.length];
		for (int i = 0; i < r.length; i++) {
			r[i] = sti(ra[i]);
		}
		return r;
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值