如果两个整数各位数字的和是一样的,则被称为是“朋友数”,而那个公共的和就是它们的“朋友证号”。例如 123 和 51 就是朋友数,因为 1+2+3 = 5+1 = 6,而 6 就是它们的朋友证号。给定一些整数,要求你统计一下它们中有多少个不同的朋友证号。

输入格式:

输入第一行给出正整数 N。随后一行给出 N 个正整数,数字间以空格分隔。题目保证所有数字小于 1。

输出格式:

首先第一行输出给定数字中不同的朋友证号的个数;随后一行按递增顺序输出这些朋友证号,数字间隔一个空格,且行末不得有多余空格。

输入样例:

8
123 899 51 998 27 33 36 12

输出样例:

4
3 6 9 26
 #include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;
int a[];
int _deal(int x)
{
int sum=;
while(x){
sum+=x%;
x/=;
}
return sum;
}
int main()
{
int n;
while(cin>>n){
for(int i=;i<n;i++){
cin>>a[i];
}
set<int> s;
set<int> ::iterator ite;
for(int i=;i<n;i++){
s.insert(_deal(a[i]));
}
int sum=s.size();
cout<<sum<<endl;
for(ite=s.begin();ite!=s.end();ite++){
if(ite==s.begin()) cout<<*ite;
else cout<<" "<<*ite;
}
cout<<endl;
}
return ;
}

PAT (Basic Level) Practice (中文)1064 朋友数 (20 分) (set)的更多相关文章

  1. PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...

  2. PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...

  3. PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642 题目描述: Being unique is so important to peo ...

  4. PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642 题目描述: A reversible prime in any n ...

  5. PAT (Advanced Level) Practice 1152 Google Recruitment (20 分)

    In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...

  6. PAT (Advanced Level) Practice 1120 Friend Numbers (20 分) (set)

    Two integers are called "friend numbers" if they share the same sum of their digits, and t ...

  7. PAT (Advanced Level) Practice 1015 Reversible Primes (20 分)

    A reversible prime in any number system is a prime whose "reverse" in that number system i ...

  8. PAT (Basic Level) Practice (中文)1078 字符串压缩与解压 (20 分) 凌宸1642

    PAT (Basic Level) Practice (中文)1078 字符串压缩与解压 (20 分) 凌宸1642 题目描述: 文本压缩有很多种方法,这里我们只考虑最简单的一种:把由相同字符组成的一 ...

  9. PAT (Basic Level) Practice (中文)1054 求平均值 (20 分) 凌宸1642

    PAT (Basic Level) Practice (中文)1054 求平均值 (20 分) 题目描述 本题的基本要求非常简单:给定 N 个实数,计算它们的平均值.但复杂的是有些输入数据可能是非法的 ...

  10. PAT (Basic Level) Practice (中文) 1050 螺旋矩阵 (25 分) 凌宸1642

    PAT (Basic Level) Practice (中文) 1050 螺旋矩阵 (25 分) 目录 PAT (Basic Level) Practice (中文) 1050 螺旋矩阵 (25 分) ...

随机推荐

  1. [redis读书笔记] 第一部分 数据结构与对象 链表

    二 链表 1.链表节点使用ListNode结构,是一个双向的链表,同时,还实现了一个控制所有ListNode的结构list: typedef struct listNode { // 前置节点 str ...

  2. XLNet:运行机制及和Bert的异同比较

    这两天,XLNet貌似也引起了NLP圈的极大关注,从实验数据看,在某些场景下,确实XLNet相对Bert有很大幅度的提升.就像我们之前说的,感觉Bert打开两阶段模式的魔法盒开关后,在这条路上,会有越 ...

  3. jenkins SSH发布文件 Publish over SSH

    jenkins 构建完成后需要一键发布,结构如下 A服务器 svn B服务器 jenkins C服务器 应用服务器 B从A拉取代码后打包成war,然后向C服务器拷贝war包 这里解决的就是远程拷贝问题 ...

  4. H5页面优化

    1. 页面优化 优化内容: 提升网页响应速度:减少请求,文件大小,页面性能 对搜索引擎,屏幕阅读器友好: 提高可读性,可维护性:规范代码 优化操作: 减少请求:小图标使用sprite拼图合并为一个图片 ...

  5. HDU 5391 水题。

    E - 5 Time Limit:1500MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  6. 【转载】Java的Vector,ArrayList,LinkedList

    首先看这两类都实现List接口,而List接口一共有三个实现类,分别是ArrayList.Vector和LinkedList.List用于存放多个元素,能够维护元素的次序,并且允许元素的重复.3个具体 ...

  7. Starting MySQL... ERROR! The server quit without updating PID file (/home/mysql-5.6.43/data/localhost.localdomain.pid).

    启动MySQL出现如下错误 May :: localhost mysqld: Starting MySQL... ERROR! The server quit without updating PID ...

  8. bootstrap4网格

    Bootstrap 4 网格系统有以下 5 个类: .col- 针对所有设备 .col-sm- 平板 - 屏幕宽度等于或大于 576px .col-md- 桌面显示器 - 屏幕宽度等于或大于 768p ...

  9. vs工程配置eslint检测环境

    vs工程打开一个js文件,会提示 "No ESLint configuration (e.g .eslintrc) found for file ......." 或 " ...

  10. 普通键盘Windows上虚拟Cherry机械键盘效果的方法

    草台班子--普通键盘Windows上虚拟Cherry机械键盘效果的方法    ​ 机械键盘以其独特的手感.绚丽的外形,还有那人神共愤的音效吸引着大批爱好者.最近iQQO 3的机械键盘效果更是吸引了更多 ...