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
 #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <stack>
#include <vector>
#include <queue>
#include <set>
using namespace std;
const int MAX = ; int A[MAX] = {}, n, cnt = , a, temp; int main()
{
// freopen("Date1.txt", "r", stdin);
scanf("%d", &n);
for (int i = ; i <= n; ++ i)
{
scanf("%d", &a);
int x = ;
while (a)
{
x += a % ;
a /= ;
}
A[x] ++;
if (A[x] == ) ++ cnt;
} printf("%d\n", cnt);
for (int i = ; i <= ; ++ i)
if (A[i] >= )
{
temp ++;
printf("%d%c", i, temp == cnt ? '\n' : ' ');
}
return ;
}

pat 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

    1120 Friend Numbers (20 分)   Two integers are called "friend numbers" if they share the sa ...

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

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

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

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

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

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

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

  8. 1023 Have Fun with Numbers (20 分)

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

  9. PAT 1120 Friend Numbers[简单]

    1120 Friend Numbers (20 分) Two integers are called "friend numbers" if they share the same ...

随机推荐

  1. 深入了解一下HTTP缓存机制

    HTTP 缓存机制作为 web 性能优化的重要手段,是Web 开发知识体系库中的一个基础环节,但是对于很多学习者来说,仅仅只是知道浏览器会对请求的静态文件进行缓存,但是为什么被缓存,缓存是怎样生效的, ...

  2. 数据结构1_java---单链表的操作,约瑟夫问题

    我们经常实用c++来建立链表,为了学习的方便,此处我使用java实现了对链表的增删改查功能 整个过程较为简单.仅供参考 流程: (1)通过内部类Node建立结点,内部变量作为指针域和数据域,并写下构造 ...

  3. Mqtt-Client

    客户端选择:paho MQTT client. 使用vs2013编译成库 需要用到paho-mqtt3a库和paho-mqtt3c库.

  4. Redis学习四(运维指南).

    一.上线规划 一般 redis 的参数配置都在 redis.conf 中,在上线前根据实际环境配置好合适参数,能有效提高 redis 的可用性. redis 的运行机器 CPU 不求核数多,但求主频高 ...

  5. Centos7 安装需要的软件环境

    Mysql 安装 下载安装 下载并安装MySQL官方的 Yum Repository wget -i -c http://dev.mysql.com/get/mysql57-community-rel ...

  6. ES6对象简洁语法

    对象(object)是 JavaScript 最重要的数据结构.ES6 对它进行了重大升级,本章介绍数据结构本身的改变及语法应用细节. 1.属性的简洁表示法 ◆ ES6 允许直接写入变量和函数,作为对 ...

  7. c#通过libreOffice实现 office文件转pdf文件

    一.安装libreOffice 点击官网下载libreOffice 二.创建一个新的项目LibreOffice 创建一个新的项目,方便后面调用 添加下面代码 public class OfficeCo ...

  8. CSP2019知识点整理

    也算是接下来二十天的复习计划吧 仅止于联赛难度左右 基础算法 字符串 char[] cstring memset() 输入无& gets(), fgets(stdin, ,); strcmp, ...

  9. 中文¥乱码 vue js

    /** * * 中文¥格式化,返回格式化后的¥100.00 * @param {any} money */utils.formatCNY = function (money) { let format ...

  10. $color$有色图

    不想看题解的请速撤离 为防被骂灌输题解,撤离缓冲区 这里没字 $Ploya$神题一道,所以我自己做不出来,颓了一部分题解. 由于理(颓题)解不(没)深(脸)中途又拿了$std$对拍(输出中间结果并qj ...