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. 《DSP using MATLAB》Problem 6.3

    天不亮又醒了,拍了张景象,这就是黎明前的黑暗吗

  2. redux笔记 进阶

    1 拆分UI组件和容器组件 import React from 'react' const AppUI = (props) =>{ return ( <div className=&quo ...

  3. vue全家桶+Koa2开发笔记(8)--开发网页

    1.使用 mongoose 动态倒入数据 mongoimport -d student -c areas areas.dat -d 后面是数据库名称: -c后面是表名称 最后是数据源 2.使用vue的 ...

  4. MySQL Session--批量KILL会话

    使用SELECT INTO OUTFILE+SOURCE批量KILL ## 查看kill_id文件是否存在 SYSTEM cat /tmp/kill_id.sql ## 如果文件存在,则先删除 sys ...

  5. C#获取当前路径的七种方法 【转载】

    //1.获取模块的完整路径. string path1 = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; // ...

  6. webpack 3 升级到 webpack 4,遇到问题解决

    报错:Error: Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead 解 ...

  7. href="javacript:;" href="javacript:void(0);" href="#"区别。。。

    一.href="javacript:;"  这种用法不正确,这么用的话会出现浏览器访问“javascript:;”这个地址的现象: 二.href="javacript:v ...

  8. Redis 基础命令

    1. 进入redis目录,启动redis cd src ./redis-server 2.  进入redis目录,启动redis客户端 cd src ./redis-cli 3. info命令 4. ...

  9. textwrap 笔记

    import textwrap s = """Look into my eyes, look into my eyes, the eyes, the eyes, the ...

  10. Flume 概述+环境配置+监听Hive日志信息并写入到hdfs

    Flume介绍Flume是Apache基金会组织的一个提供的高可用的,高可靠的,分布式的海量日志采集.聚合和传输的系统,Flume支持在日志系统中定制各类数据发送方,用于收集数据:同时,Flume提供 ...