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. PHP 调试时中断了事务

    1.错误:Uncaught PDOException: SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try res ...

  2. MySQL 数据库的设计规范

    网址 :http://blog.csdn.net/yjjm1990/article/details/7525811 1.文档的建立日期.所属的单位.2.数据库的命名规范.视图.3.命名的规范:1)避免 ...

  3. Cocos2d-x 学习笔记(11.5) SkewTo SkewBy

    1. SkewTo SkewBy node朝X和Y方向的歪斜.SkewTo是SkewBy的父类. 1.1 成员变量 create方法 // 两者成员变量一致 float _skewX; float _ ...

  4. grunt前端自动构建工具初级使用

    好啦,今天来和大家谈谈grunt 害怕与社会脱轨,所以自己研究了一下,简单说说我梳理完的grunt 首先要知道为什么使用grunt 1.grunt可以检测js.css文件内部是否有错误 2. grun ...

  5. Spring Data - Spring Data JPA 提供的各种Repository接口

    Spring Data Jpa 最近博主越来越懒了,深知这样不行.还是决定努力奋斗,如此一来,就有了一下一波复习 演示代码都基于Spring Boot + Spring Data JPA 传送门: 博 ...

  6. 数据结构(三十三)最小生成树(Prim、Kruskal)

    一.最小生成树的定义 一个连通图的生成树是一个极小的连通子图,它含有图中全部的顶点,但只有足以构成一棵树的n-1条边. 在一个网的所有生成树中,权值总和最小的生成树称为最小代价生成树(Minimum ...

  7. Spring Boot 日志处理你还在用Logback?

    ▶ Log4j2 性能 https://logging.apache.org/log4j/2.x/performance.html ▶ Spring Boot 依赖与配置 Maven 依赖 <! ...

  8. 安装Java环境

    一.下载JDK https://www.oracle.com/technetwork/java/javase/downloads/index.html 二.exe安装 默认路径 C:\Program ...

  9. API gateway 之 kong 基本介绍 (一)

    一.API网关概念介绍 API 网关,即API Gateway,是大型分布式系统中,为了保护内部服务而设计的一道屏障,可以提供高性能.高可用的 API托管服务,从而帮助服务的开发者便捷地对外提供服务, ...

  10. [考试反思]0929csp-s模拟测试55:消逝

    菜得过分. 面对T1的大板子不知所措,然后T2的贪心不小心把排序语句删了... T1这种大模板啊...其实我是觉得我能打出来的,然后先用一个小时码了一个2k. 然后做T2想贪心就出来了.十分钟码完T3 ...