1120 Friend Numbers (20 分)
 

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<bits/stdc++.h>
using namespace std;
typedef long long ll; int main(){
int t;
cin >> t;
set<int> st; while(t--){
string s;
cin >> s;
int sum = ;
for(int i=;i < s.size();i++){
sum += s[i] - '';
}
st.insert(sum);
} cout << st.size() << endl;
int cnt = ; for(auto it=st.begin();it!=st.end();it++){
cout << *it;
cnt++;
if(cnt!=st.size())cout << " ";
} return ;
}

这题白给

最后一行无空格可以这样写

if(it != s.begin()) printf(" ");
 

PAT 1120 Friend Numbers的更多相关文章

  1. PAT 1120 Friend Numbers[简单]

    1120 Friend Numbers (20 分) Two integers are called "friend numbers" if they share the same ...

  2. pat 1120 Friend Numbers(20 分)

    1120 Friend Numbers(20 分) Two integers are called "friend numbers" if they share the same ...

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

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

  4. 1120 Friend Numbers (20 分)

    1120 Friend Numbers (20 分) Two integers are called "friend numbers" if they share the same ...

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

  6. PAT甲题题解-1120. Friend Numbers (20)-水题

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789775.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  7. PAT A1120 Friend Numbers (20 分)——set

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

  8. PAT 1100 Mars Numbers[难]

    1100 Mars Numbers (20 分) People on Mars count their numbers with base 13: Zero on Earth is called &q ...

  9. PAT 1100. Mars Numbers

    People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...

随机推荐

  1. Android-Gradle(五)

    Android studio不仅允许你为你的app和依赖库创建模块,同时也可为Android wear,Android TV,Google App Engine等创建模块,而这些单独的模块又可以在一个 ...

  2. 【winform】serialPort 串口

    一. 1.串口通信简单实现 该来的总会来的,学做硬件的,串口这个东西必须得门清. 俗话说的好,不会做串口助手的电子工程师不是好程序员.

  3. redis使用总结(一)(redis客户端使用)

    NoSQL 摘自百度百科 NoSQL,泛指非关系型的数据库.随着互联网web2.0网站的兴起,传统的关系数据库在应付web2.0网站,特别是超大规模和高并发的SNS类型的web2.0纯动态网站已经显得 ...

  4. 第十六节 BOM基础

    打开.关闭窗口 open:蓝色理想运行代码功能 <button onclick="window.open('http://www.baidu.com')">打开窗口&l ...

  5. vue-自主研发非父子关系组件之间通信的问题

    相信很多人都知道解决组件间通信:vuex,今天的主角不是它. element-ui里解决组件间通信的思路:emitter.js ,但是如果你拿来你会发现它解决的是父子组件之间的通信问题.如果我们通信的 ...

  6. 使用 Nginx 内置 $http_user_agent 来区分( 电脑 pc、手机 mobile、平板 pad )端的内容访问

    location / { #pc端内容访问 set $flag "pc"; set $num 1; set $hua "${http_user_agent}"; ...

  7. NOIP 2017 宝藏 - 动态规划

    题目传送门 传送门 题目大意 (家喻户晓的题目不需要题目大意) 设$f_{d, s}$表示当前树的深度为$d$,与第一个打通的点连通的点集为$s$. 每次转移的时候不考虑实际的深度,深度都当做$d$, ...

  8. java中的循环方法(附带本人遇到的坑)

    java循环结构 顺序结构的程序语句只能 被执行一次.如果你要同样的操作执行多次,就需要使用循环结构. java中有三种主要的循环结构: 1.while 循环 2.do...while 循环 3.fo ...

  9. linux服务基础(一)之CentOS6编译安装httpd2.4

    安装http-2.4 Http依赖于apr-1.4+,apr-util-1.4+ CentOS6上默认是apr-1.3,apr-util1.3 先编译安装apr-1.5,apr-util-1.5 开始 ...

  10. CF786B Legacy

    思路 线段树优化建图 基本思想就是要把一个区间连边拆成log个节点连边, 然后一颗入线段树,一颗出线段树,出线段树都由子节点向父节点连边(可以从子区间出发),入线段树从父节点向子节点连边(可以到达子区 ...