import java.io.*;
import java.util.Set;
import java.util.TreeSet;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(bf.readLine());
String[] str = bf.readLine().split(" ");
//第一次使用TreeSet,相比于HashSet的无序性,能够对存入的数据排好序
Set<Integer> set = new TreeSet<Integer>();
//将所有朋友数存入set中,set会排除掉重复数值
for (int i = 0; i < str.length; i++) {
if (set.contains(adad(str[i]))) {
continue;
} else {
set.add(adad(str[i]));
}
}
//输出朋友数个数
System.out.println(set.size());
//遍历set集合,由于已经排好序,从头到尾遍历输出即可
boolean isFirst = true;
for (int id : set) {
if (!isFirst) {
System.out.print(" ");
}
System.out.print(id);
isFirst = false;
}
}
//返回三位加和
public static int adad(String str) {
int n = Integer.parseInt(str);
int sum = 0;
/*
int ge = n % 10;
int shi = n % 100 / 10;
int bai = n / 100;
*/
while(n!=0){
sum+=n%10;
n/=10;
}
return sum;
}
}
PAT_B_1064_Java(20分)
猜你喜欢
转载自blog.csdn.net/qq_43511405/article/details/107423367
今日推荐
周排行