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. Python中元组、列表、字典的遍历和相互转化

    一.元组,列表,字典的遍历 1.1 元组的遍历 元组的遍历借助 range() 函数,基本思想是通过元组的长度使用for循环进行遍历,代码如下:     fruits=("apple&quo ...

  2. idea快捷键的修改

    快捷键Ctrl+Alt+s,快速进入intellij idea设置项,点击Keymap,如图: 点击Main menu,再点开Code,如图: 点击Completion,再点击Basic,右键,如图 ...

  3. elasticsearch技术解析与实战(一) 入门和索引

    GET _cat/nodes GET _cat/health GET _cat/shards GET http://10.37.84.124:9200/secisland?pretty { " ...

  4. AI 学习

    极简状态机: /* 脚本名称: 脚本作者: 建立时间: 脚本功能: 版本号: */ using UnityEngine; using System.Collections; namespace Voi ...

  5. Unity项目架构设计与开发管理 学习

    视频地址:https://v.qq.com/x/page/d016340mkcu.html assetstore save manager

  6. Python实例属性限制(__slots__)

    Python的动态绑定可以在程序运行的过程中对实例或class加上功能,但是如果我们想要限制实例的属性怎么办呢?更改内容请参考:Python学习指南 正常情况下,当我们定义了一个class,创建了一个 ...

  7. 编写一个函数实现n^k,使用递归实现

    思路:例如2的3次方.可以分解为2乘2的2次方,而2的2次方又可以分解为2乘2的以此方法,以此类推. #include<stdio.h> int Find_num(int n,int k) ...

  8. window.onload与$(document).ready()

    window.onload是原生JS事件,$(document).ready()是Jquery实现的与其作用类似的事件. 二者区别如下: 1.执行时间不同 $(document).ready()是DO ...

  9. 建立你第一个 Outlook Add-in

    最近因为工作需要,研究了下Outlook Add-in 和 Graph API.下面带大家建立一个Hello World 项目 建立Add-in 先前需求: Node.js 使用cmd/PowerSh ...

  10. redis之 Redis持久化配置

    Redis持久化配置 Redis的持久化有2种方式   1快照  2是日志 Rdb快照的配置选项 save 900 1      // 900内,有1条写入,则产生快照 save 300 1000   ...