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

题意:统计数的各位数字之和,并升序输出

分析:水题
 /**
 * Copyright(c)
 * All rights reserved.
 * Author : Mered1th
 * Date : 2019-02-27-21.33.59
 * Description : A1120
 */
 #include<cstdio>
 #include<cstring>
 #include<iostream>
 #include<cmath>
 #include<algorithm>
 #include<string>
 #include<unordered_set>
 #include<map>
 #include<vector>
 #include<set>
 using namespace std;
 ;
 set<int> ans;
 int main(){
 #ifdef ONLINE_JUDGE
 #else
     freopen("1.txt", "r", stdin);
 #endif
     int n;
     cin>>n;
     string str;
     ;i<n;i++){
         cin>>str;
         ;
         int len=str.size();
         ;j<len;j++){
             sum+=str[j]-';
         }
         ans.insert(sum);
     }
     printf("%d\n",ans.size());
     for(auto it=ans.begin();it!=ans.end();it++){
         if(it!=ans.begin()) printf(" %d",*it);
         else printf("%d",*it);
     }
     ;
 }


1120 Friend Numbers (20 分)的更多相关文章

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

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

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

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

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

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

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

  6. 1023 Have Fun with Numbers (20 分)

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

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

  8. 【PAT甲级】1023 Have Fun with Numbers (20 分)

    题意: 输入一个不超过20位的正整数,问乘2以后是否和之前的数组排列相同(数字种类和出现的个数不变),输出Yes或No,并输出乘2后的数字. AAAAAccepted code: #define HA ...

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

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

  10. A1100 Mars Numbers (20 分)

    一.技术总结 这一题可以使用map进行想打印存储,因为数据量不是很大,最后直接输出.但是还是觉得没有必要. 主要考虑两个问题,首先是数字转化为字符串,实质就是进制转化,但是有点不同,如果十位有数字,个 ...

随机推荐

  1. #505 1&2 A-C 后面未完成

    A. Doggo Recoloring 题目意思是给一个字符串(都是小写字母),如果有两个字符相同,我们可以将这两个字符变成其他字符,问能不能使字符串字母都一样 思路  有两个相同字符时就能:  字符 ...

  2. 炫龙笔记本的gtx965m显卡玩游戏很卡

    这是我遇到的问题,我2016年10月份这样买了一款笔记本,主要看的是性价比吧!神舟.炫龙都是性价比,所以买了炫龙笔记本 配置如下 cpu:i7 4870hq 显卡:gtx965m 内存条:16G 固态 ...

  3. AtCoder Grand Contest 031 简要题解

    AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...

  4. Can’t call setState (or forceUpdate) on an unmounted component 警告处理方法

    Can’t call setState (or forceUpdate) on an unmounted component Warning: Can't call setState (or forc ...

  5. 05基于python玩转人工智能最火框架之TensorFlow基础知识

    从helloworld开始 mkdir mooc # 新建一个mooc文件夹 cd mooc mkdir 1.helloworld # 新建一个helloworld文件夹 cd 1.helloworl ...

  6. 嵌入式LINUX设置时间

    date -s "2018-12-15 08:55:00" 安装NTP从网络获取时间 基于Linux的嵌入式开发,需要用到本地的时间,但是网上找了很多修改时间的命令,但大多是Lin ...

  7. 笔记:Python 默认参数必须指向不变对象

    笔记:Python 默认参数必须指向不变对象 学习记录 >>> def add_end(L=[]): L.append('END') return L >>> ad ...

  8. maven的profile

    https://elim.iteye.com/blog/1900568 简介:配置不同环境要使用的profile,再idea操作画面可以选

  9. apache2 配置虚拟主机

    查看 apache2 的配置位置: whereis apache2 我的在:/etc/apache2 sites-available  文件夹下面放的就是 虚拟站点的配置文件: 随便复制一个改改: c ...

  10. jmeter --- 搭建持续集成接口测试平台(Jenkins+Ant+Jmeter)

    jmeter --- 搭建持续集成接口测试平台(Jenkins+Ant+Jmeter) 一.环境准备: 1.JDK:http://www.oracle.com/technetwork/java/jav ...