1228: 数字游戏
时间限制: 1 Sec 内存限制: 128 MB
题目描述
ykc和cds在玩一个数字游戏,ykc会给出n个数,cds需要告诉ykc有多少个数只出现过一次,由于数字太多,cds慌得不行。请你帮助cds快速求出答案。
输入
输入包括多组数据。以n等于0结束
每组数据中:
第一行为一个整数n,表示整数的数量。
第二行输入n个整数。
所有输入的数均小于100000。
输出
输出答案。
样例输入
5 1 2 3 3 2 7 1 2 3 4 5 5 6 0
样例输出
1 5
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
Map<String, Integer> tes = new HashMap<String,Integer>();
while(true){
int n =sc.nextInt();
if(n == 0){
break;
}
for (int i = 0; i < n; i++) {
int temp = sc.nextInt();
if(tes.get(temp+"")==null)
tes.put(temp+"", 1);
else{
int t = tes.get(temp+"")+1;
tes.put(temp+"", t);
}
}
int p = 0;
for (String key : tes.keySet()) {
if(tes.get(key)==1)
p++;
}
System.out.println(p);
tes.clear();
}
}
}
/**************************************************************
Problem: 1228
User: 20161514325
Language: Java
Result: 正确
Time:1434 ms
Memory:66808 kb
****************************************************************/