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
题意:统计数的各位数字之和,并升序输出
分析:水题
/**
* 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 分)的更多相关文章
- 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 (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 (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甲级】1023 Have Fun with Numbers (20 分)
题意: 输入一个不超过20位的正整数,问乘2以后是否和之前的数组排列相同(数字种类和出现的个数不变),输出Yes或No,并输出乘2后的数字. AAAAAccepted code: #define HA ...
- PAT甲题题解-1120. Friend Numbers (20)-水题
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789775.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- A1100 Mars Numbers (20 分)
一.技术总结 这一题可以使用map进行想打印存储,因为数据量不是很大,最后直接输出.但是还是觉得没有必要. 主要考虑两个问题,首先是数字转化为字符串,实质就是进制转化,但是有点不同,如果十位有数字,个 ...
随机推荐
- 欧拉函数 已经优化到o(n)
欧拉函数 ψ(x)=x*(1-1/pi) pi为x的质数因子 特殊性质(图片内容就是图片后面的文字) 欧拉函数是积性函数——若m,n互质, ψ(m*n)=ψ(m)*ψ(n): 当n为奇数时, ψ ...
- 浅谈log4j-6-xml配置 转自godtrue
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration SY ...
- 【JVM】jvm虚拟机参数解析
转载:https://blog.csdn.net/see__you__again/article/details/51998038不管是YGC还是Full GC,GC过程中都会对导致程序运行中中断,正 ...
- day05 Spring中自定义注解的用处-之获取自定义的Servie
PS: 在RPC远程调用中,想要获取自定义的service的方法,就得自定义标签遍历拿到方法 PS:在spring中,两个最核心的 概念是aop和ioc,aop其实就是动态代理. ioc 就是解决对象 ...
- vuex简介(转载)
安装.使用 vuex 首先我们在 vue.js 2.0 开发环境中安装 vuex : npm install vuex --save 然后 , 在 main.js 中加入 : import vuex ...
- VM安装系统时提示硬件不支持(unsupported hardware detected)
修改一下虚拟机配置,把CD/DVD中使用的autoinst.iso替换成需要安装的系统镜像文件 然而,后面发现还是会报这个错,不过,却可以正常安装下去.但是如果不修改这里的话,安装系统时会出错
- linux日志管理
//有关当前登录用户的信息记录在文件utmp中 //登录进入和退出纪录在文件wtmp中 [root@bogon python]# who //who命令查询utmp文件并报告当前登录的每个用户 /va ...
- Modern Data Lake with Minio : Part 2
转自: https://blog.minio.io/modern-data-lake-with-minio-part-2-f24fb5f82424 In the first part of this ...
- 浅析 阿里 OceanBase 双十一 淘宝天猫 天量交易 承载能力 原理
我们先看看 这 2 篇文章: <秘诀!支付宝支撑双十一4200万次/秒的数据库请求峰值的技术实现> https://mp.weixin.qq.com/s?__biz=MzI3MzEzMD ...
- i++和++i的笔试题
i = ++i + i++ + i++ + i++; 把每个 i++或者++i看作一个部分,他们的分别再下一个 i++或者++i改变,中途赋值的话,就返回这个部分的值 来自:https://www.j ...