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. java 自带的工具

    前辈说,java的基本功的好坏,一个方面要看是否能熟练使用jdk bin下的工具使用情况. 自己整理一下使用的工具. ■ javac 一个编译java的工具,进入java所在文件的路径后,javac ...

  2. 转载 React.createClass 对决 extends React.Component

    先给出结论,这其实是殊途同归的两种方式.过去我们一般都会使用 React.createClass 方法来创建组件,但基于 ES6 的小小语法糖,我们还可以通过 extends React.Compon ...

  3. gitingore && opensource license 自动生成的网站

    老外就是爱搞事情,总有一些方便我们开发的小工具出来,比如gitignore以及开源软件许可协议的 gitingore 生成的 地址 https://www.gitignore.io/ 使用 搜索的地方 ...

  4. 模拟实现strncpy,strncat,strncmp

    1.模拟实现strncpy  <1.>strncpy相比于strcpy增加了size_t参数可以实现最多拷贝的字节数<2.>(size_t不可以超出拷贝存放的内存大小)来保证不 ...

  5. Array.asList()

    package study.stage2;import java.util.*; /** * Created by Sandy.Liu on 2017/7/19. */public class Asl ...

  6. python之路---09 初始函数 参数

    二十七.初始函数 1.函数: 对代码块和功能的封装和定义 2.格式及语法 def  函数名()           #  定义 函数体 函数名()              #  调用 3.    r ...

  7. 一个简单的web.py论坛

    一.概述 forum是一个简单的web.py论坛,后端采用Python+web.py+MySQL,前端采用HTML+CSS+JavaScript+jQuery+RequireJS. 该论坛的主要功能包 ...

  8. windows删除文件或目录CMD命令

    rd/s/q 盘符:\某个文件夹  (强制删除文件文件夹和文件夹内所有文件)del/f/s/q 盘符:\文件名  (强制删除文件,文件名必须加文件后缀名)

  9. hbase java 基本例子

    一下代码实用  0.99.0 以后的版本. package hadoop; import java.io.IOException; import java.util.ArrayList; import ...

  10. es query_string 和 match 的区别

    默认使用 空格拆分成 多个 子项,并且 每个子项 都会去分词 查询.可以通过 default_operator 指定  子项之间的关系.默认是 或 . 然后 每个 子项前面可以使用 -+ 指定必须有 ...