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 1.

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 <iostream>
#include <set>
#include <string>
using namespace std;
int main()
{
int n;
string s;
set<int>res;
cin >> n;
while (n--)
{
cin >> s;
int sum = ;
for (auto a : s)
sum += a - '';
res.insert(sum);
}
cout << res.size() << endl;
for (auto a : res)
cout << (a == *(res.begin()) ? "" : " ") << a;
cout << endl;
return ;
}

PAT甲级——A1120 Friend Numbers【20】的更多相关文章

  1. PAT甲级 1120. Friend Numbers (20)

    1120. Friend Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Two in ...

  2. PAT甲级——1100 Mars Numbers (字符串操作、进制转换)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90678474 1100 Mars Numbers (20 分) ...

  3. PAT 甲级 1035 Password (20 分)

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

  4. PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)

    1073 Scientific Notation (20 分)   Scientific notation is the way that scientists easily handle very ...

  5. PAT 甲级 1046 Shortest Distance (20 分)(前缀和,想了一会儿)

    1046 Shortest Distance (20 分)   The task is really simple: given N exits on a highway which forms a ...

  6. PAT 甲级 1042 Shuffling Machine (20 分)(简单题)

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

  7. PAT 甲级 1041 Be Unique (20 分)(简单,一遍过)

    1041 Be Unique (20 分)   Being unique is so important to people on Mars that even their lottery is de ...

  8. PAT甲级——A1152 GoogleRecruitment【20】

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

  9. PAT甲级——A1148 WerewolfSimpleVersion【20】

    Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and th ...

随机推荐

  1. vue组件添加鼠标滚动事件

    在一个组件标签上加鼠标滚动事件,应该写成    @mousewheel.native

  2. thinlphp配置加载

    在ThinkPHP中,一般来说应用的配置文件是自动加载的,加载的顺序是: 惯例配置->应用配置->模式配置->调试配置->状态配置->模块配置->扩展配置-> ...

  3. hdu多校第八场 1011 (hdu6667) Roundgod and Milk Tea 二分图匹配

    题意: 有若干个班,每个班有些人要喝奶茶,也提供一些奶茶,一人喝一杯,但是自己班的人不能喝自己班的奶茶,求最多能有多少人喝上奶茶. 题解: 典型的二分图匹配问题,学生在左,奶茶在右,学生和非自己班的奶 ...

  4. idea中选中了一个变量名,会高亮显示位于别的地方的这个变量名,那么怎么修改其他地方的高亮颜色

  5. AtCoder ABC 128E Roadwork

    题目链接:https://atcoder.jp/contests/abc128/tasks/abc128_e 题目大意 在一条路上(这条路可以看做坐标轴 x 轴从 0 开始方向为正无穷方向的射线),有 ...

  6. 编译Solr4.72 源码没有成功

    最近需要用到solr,查询Hbase里面的数据,编译Solr的时候遇到了点问题: 下了solr的源码后需要用ant自己编译: 源码下载地址:https://svn.apache.org/repos/a ...

  7. 关于合并pdf文件出现的问题

    输出端出现以下问题: PdfReadWarning: Xref table not zero-indexed. ID numbers for objects will be 解决方案: import ...

  8. Java设计模式(一)外观模式(门面模式)- 结构型模式

    模式的定义 门面模式(Facade Pattern)也叫做外观模式,是一种比较常用的封装模式,其定义如下:要求一个子系统的外部与其内部通信必须通过一个统一的对象进行.门面模式提供一个高层次的接口,使得 ...

  9. Java异常类及处理

    异常概述:运行时发生的不正常情况 在java中用类的形式对不正常的情况进行了描述和封装对象. 描述不正常的类,称之为异常类. 异常就是java通过面向对象的思想将问题封装成了对象,用异常类对其进行描述 ...

  10. xargs - 从标准输入重建并执行命令行

    总览 (SYNOPSIS) xargs [-0prtx] [-e[eof-str]] [-i[replace-str]] [-l[max-lines]] [-n max-args] [-s max-c ...