pat 1120 Friend Numbers(20 分)
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 104.
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 分)的更多相关文章
- 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 ...
- PAT 1120 Friend Numbers
1120 Friend Numbers (20 分) Two integers are called "friend numbers" if they share the sa ...
- 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 ...
- PAT甲级 1120. Friend Numbers (20)
1120. Friend Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Two in ...
- 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 ...
- 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 ...
- 1069 The Black Hole of Numbers (20分)
1069 The Black Hole of Numbers (20分) 1. 题目 2. 思路 把输入的数字作为字符串,调用排序算法,求最大最小 3. 注意点 输入的数字的范围是(0, 104), ...
- 1023 Have Fun with Numbers (20 分)
1023 Have Fun with Numbers (20 分) Notice that the number 123456789 is a 9-digit number consisting ...
- PAT 1120 Friend Numbers[简单]
1120 Friend Numbers (20 分) Two integers are called "friend numbers" if they share the same ...
随机推荐
- JavaScript函数总结—越努力,越幸运!
JavaScript 函数总结 JavaScript为web的编程脚本语言. JavaScript由三部分组成:emc(语法) dom(文档对象模型) bom(浏览器对象模型). [函数的定义] 1. ...
- 数据结构2_java---栈,括号匹配
package Main; import java.util.Scanner; import javax.swing.text.html.HTMLDocument.HTMLReader.Isindex ...
- 实用---eclipse中的代码提示功能
Eclipse 的代码提示功能,具体配置 1. 打开Eclipse ,然后“window”→“Preferences” 2. 选择“java”,展开,“Editor”,选择“Content Assis ...
- tkinter基础-标签、按钮
本节内容: 明白标签.按钮的使用 实现简单的点击界面 Tkinter 简称tk,在python中属于内置模块,不需要进行安装,可直接引用,import tkinter 一. 首先我们做一个如图所示的图 ...
- Uipath 勾选checkbox
东京IT青年前线 http://www.rpatokyo.com/ Uipath 勾选checkbox 使用check Activity可以对check box 复选框进行勾选. 虽然Click也可以 ...
- NOIP2018货币系统
题目大意 给出一组数,求出其中共有多少数不能被其他数表示 解题思路 法一:可爱的动态规划 这个思路还是比较好想的(也比较好写?) 有依赖关系的背包,思路这道题是差不多的 填满型01背包 (关于代码) ...
- 在已有 Windows10 系统的基础上,安装 Ubuntu17.10 系统(新版 BIOS)
1.第一步,下载Ubuntu系统镜像 2.第二步,制作启动U盘,使用UltralSO,步骤:打开文件——选择iso文件——启动——写入硬盘映像——选择U盘——写入 3.第三步,分区,在Windows徽 ...
- Leetcode(9)回文数
Leetcode(9)回文数 [题目表述]: 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 第一次:直接全部转 执行用时:148 ms: 内存消耗:13.4 ...
- Leetcode Tags(2)Array
一.448. Find All Numbers Disappeared in an Array 给定一个范围在 1 ≤ a[i] ≤ n ( n = 数组大小 ) 的 整型数组,数组中的元素一些出现了 ...
- ARToolKit-unity
ARToolKit为开源的AR库,相对于高通和easyAr有几点特点: 1)开源 2)识别项目可以动态添加(详细在后) 3)识别文件可以本地生成 4)目前只能识别图片(目前为.jpg格式) 下边开始详 ...