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. XGBoost 与 Boosted Tree

    http://www.52cs.org/?p=429 作者:陈天奇,毕业于上海交通大学ACM班,现就读于华盛顿大学,从事大规模机器学习研究. 注解:truth4sex  编者按:本文是对开源xgboo ...

  2. Unity 让物体朝摄像机观察方向移动,已摇杆方向转向

    using System.Collections;using System.Collections.Generic;using UnityEngine; [RequireComponent(typeo ...

  3. h5完美实现无刷新上传并附带上传效果

    附带上传源码如下: <!DOCTYPE html> <html> <head> <title>测试上传功能</title> <meta ...

  4. ajax的三次封装简单概况

    原生ajax:                readyState         准备状态                status             页面状态               ...

  5. [Python数据挖掘]第3章、数据探索

    1.缺失值处理:删除.插补.不处理 2.离群点分析:简单统计量分析.3σ原则(数据服从正态分布).箱型图(最好用) 离群点(异常值)定义为小于QL-1.5IQR或大于Qu+1.5IQR import ...

  6. 编程类-----matlab基础语法复习(1)

    2019年美赛随笔记录: 具体功能:基础语法+基本运算+画图+矩阵+excel读取....... 所遇问题及其解决方案:         1.   que:matlab中plot画图无法复制下来图片? ...

  7. Linux 设置系统时间和时区2.Ubuntu

    查看当前时间状态 timedatectl status 设置时区 sudo dpkg-reconfigure tzdata Asia shanghai

  8. Java中的抽象

    什么是抽象类? 如果一个类没有足够的信息去描述一个具体的对象,那么这样的类我们就称它为抽象类.这很好理解,就如同动物是一个很广泛的概念,由于在动物这个类里,我们无法用很详细的信息去描述狗狗这个具体的对 ...

  9. selenium 文件上传

    一般分两个场景:一种是input标签,这种可以用selenium提供的send_keys()方法轻松解决: 另外一种非input标签实现起来比较困难,可以借助autoit工具或者SendKeys第三方 ...

  10. 论文笔记:Learning regression and verification networks for long-term visual tracking

    Learning regression and verification networks for long-term visual tracking 2019-02-18 22:12:25 Pape ...