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. windows下python环境安装

    虽然是windows下安装的方式,但是linux也差不多哈: 1,首先安装python 这个是菜鸟教程的安装介绍页面,其实很清晰了:http://www.runoob.com/python3/pyth ...

  2. tcp ip 协议安全

    ARP(地址解析协议) 地址解析协议,即ARP(Address Resolution Protocol),是根据IP地址获取物理地址的一个TCP/IP协议.主机发送信息时将包含目标IP地址的ARP请求 ...

  3. mySQL的行转列

    因为MYSQL里边没有  PIVOT      现记录:   原表格:   mysql语句: SELECT MAX(CASE WHEN corol='红' THEN NUM else 0 END) A ...

  4. docker运行镜像报错:"write init-p: broken pipe"

    docker: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting cont ...

  5. 问题 1690: 算法4-7:KMP算法中的模式串移动数组

    题目链接:https://www.dotcpp.com/oj/problem1690.html 题目描述 字符串的子串定位称为模式匹配,模式匹配可以有多种方法.简单的算法可以使用两重嵌套循环,时间复杂 ...

  6. CentOS7 手动部署flannel并启用vxlan

    本以为docker准备妥当之后,就可以直接上k8s了,结果yum install kubernetes,报错:Error: docker-ce conflicts with docker-1.9.1 ...

  7. 软件测试实验二----selenium、katalon、junit

    1.安装firefox和seleniumIDE.katalon 安装按成后在Firefox中有seleniumIDE.katalon的图标 2.使用katalon导出测试脚本 点击katalon的插件 ...

  8. Path Analyzer Pro出现raw socket问题

    使用windows7,8以及10平台运行一个traceroute liketools软件,名为Path Analyzer Pro 2.7,遇到raw socket问题,如图: 原因是raw socke ...

  9. 算法(第四版)C# 习题题解——2.5

    写在前面 整个项目都托管在了 Github 上:https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp 查找更方便的版本见:https ...

  10. javascript实现继承的三种方式

    一.原型链继承  function Parent(){} function Child(){} Child.prototype = new Parent(); 通过对象child的prototype属 ...