Two integers are called "friend numbers" if they share the same sum of their digits, and the sum is their "friend ID". For example, 123 and 51 are friend numbers since 1+2+3 = 5+1 = 6, and 6 is their friend ID. Given some numbers, you are supposed to count the number of different frind ID's among them.

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N. Then N positive integers are given in the next line, separated by spaces. All the numbers are less than 10​4​​.

Output Specification:

For each case, print in the first line the number of different frind ID's among the given integers. Then in the second line, output the friend ID's in increasing order. The numbers must be separated by exactly one space and there must be no extra space at the end of the line.

Sample Input:

8
123 899 51 998 27 33 36 12

Sample Output:

4
3 6 9 26

 #include <stdio.h>
#include <set>
using namespace std;
int main(){
int n;
scanf("%d",&n);
set<int> s;
for(int i=;i<n;i++){
int tmp;
scanf("%d",&tmp);
int num=;
while(tmp!=){
num+=tmp%;
tmp/=;
}
s.insert(num);
}
int cnt=;
printf("%d\n",s.size());
for(auto it=s.begin();it!=s.end();it++){
printf("%d",*it);
cnt++;
if(cnt!=s.size())printf(" ");
}
}

注意点:用set很方便,但set的指针迭代器只有加法操作没有减法操作,所以判断输出空格不能靠迭代器指针,还是要另外加一个变量

PAT A1120 Friend Numbers (20 分)——set的更多相关文章

  1. PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642 题目描述: Notice that the number ...

  2. PAT 甲级 1069 The Black Hole of Numbers (20 分)(内含别人string处理的精简代码)

    1069 The Black Hole of Numbers (20 分)   For any 4-digit integer except the ones with all the digits ...

  3. PAT 甲级 1023 Have Fun with Numbers (20 分)(permutation是全排列题目没读懂)

    1023 Have Fun with Numbers (20 分)   Notice that the number 123456789 is a 9-digit number consisting ...

  4. 1069 The Black Hole of Numbers (20分)

    1069 The Black Hole of Numbers (20分) 1. 题目 2. 思路 把输入的数字作为字符串,调用排序算法,求最大最小 3. 注意点 输入的数字的范围是(0, 104), ...

  5. 1023 Have Fun with Numbers (20 分)

    1023 Have Fun with Numbers (20 分)   Notice that the number 123456789 is a 9-digit number consisting ...

  6. pat 1035 Password(20 分)

    1035 Password(20 分) To prepare for PAT, the judge sometimes has to generate random passwords for the ...

  7. pat 1008 Elevator(20 分)

    1008 Elevator(20 分) The highest building in our city has only one elevator. A request list is made u ...

  8. PAT 甲级 1061 Dating (20 分)(位置也要相同,题目看不懂)

    1061 Dating (20 分)   Sherlock Holmes received a note with some strange strings: Let's date! 3485djDk ...

  9. PAT 甲级 1035 Password (20 分)(简单题)

    1035 Password (20 分)   To prepare for PAT, the judge sometimes has to generate random passwords for ...

  10. PAT 1042 Shuffling Machine (20 分)

    1042 Shuffling Machine (20 分)   Shuffling is a procedure used to randomize a deck of playing cards. ...

随机推荐

  1. elasticsearch6.7 01.入门指南(2)

    2.安装(略) 默认情况下,elasticsearch 使用端口 9200 来访问它的 REST API.如果有必要,该端口也可以配置 3.探索集群 3.1 The REST API 既然我们已经启动 ...

  2. 漫画 | Spring AOP的底层原理是什么?

    1.Spring中配置的bean是在什么时候实例化的? 2.描述一下Spring中的IOC.AOP和DI IOC和AOP是Spring的两大核心思想 3.谈谈IOC.AOP和DI在项目开发中的应用场景 ...

  3. Python全栈学习_day003知识点

    今日大纲: . 基础数据类型 总览 . int . bool . str . for循环 1. 基础数据类型 总览 int: 用于计算,计数等 str:'这些内容',用户少量数据的存储,便于操作 bo ...

  4. 前端周报:前端面试题及答案总结;JavaScript参数传递的深入理解

    1.2017前端面试题及答案总结 |掘金技术征文 "金三银四,金九银十",用来形容求职最好的几个月.但是随着行业的饱和,初中级前端er就业形势不容乐观. 行业状态不可控,我们能做的 ...

  5. loadrunner 运行脚本-命令行运行脚本

    Loadrunner 运行脚本-命令行运行脚本   by:授客 QQ:1033553122 脚本所在目录 Run-time Settings->Additional Attributes设置   ...

  6. wap2app(六)-- wap2app的原生标题头无法隐藏

    大概有一个星期没有用HBuilder打包,今天更新了HBuilder版本再继续打包,就出现了一系列问题.其中有一个就是打包之后,除首页外,其他页面多出了原生标题,如下图: 查阅资料,打开 sitema ...

  7. linux networking

    ip route解读 default via 192.168.1.1 dev wlan0 dev wlan0 proto kernel scope link src 192.168.1.100 htt ...

  8. [20180801]insert导致死锁.txt

    [20180801]insert导致死锁.txt --//链接http://www.itpub.net/thread-2104135-2-1.html的讨论,自己有点疏忽了,插入主键相同也会导致死锁. ...

  9. iTween for Unity

    你曾经在你的游戏中制作过动画吗?问这个问题可能是愚蠢的,几乎每个Game都有动画,虽然有一些没有,但你必须处理有动画和没有动画.让我们结识 ITween. iTween 官方网站:http://itw ...

  10. 浅谈tidb事务与MySQL事务之间的区别

    MySQL是我们日常生活中常见的数据库,他的innodb存储引擎尤为常见,在事务方面使用的是扁平事务,即要么都执行,要么都回滚.而tidb数据库则使用的是分布式事务.两者都能保证数据的高一致性,但是在 ...