PAT甲级——A1120 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 1.
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 <set>
#include <string>
using namespace std;
int main()
{
int n;
string s;
set<int>res;
cin >> n;
while (n--)
{
cin >> s;
int sum = ;
for (auto a : s)
sum += a - '';
res.insert(sum);
}
cout << res.size() << endl;
for (auto a : res)
cout << (a == *(res.begin()) ? "" : " ") << a;
cout << endl;
return ;
}
PAT甲级——A1120 Friend Numbers【20】的更多相关文章
- PAT甲级 1120. Friend Numbers (20)
1120. Friend Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Two in ...
- PAT甲级——1100 Mars Numbers (字符串操作、进制转换)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90678474 1100 Mars Numbers (20 分) ...
- PAT 甲级 1035 Password (20 分)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...
- PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very ...
- PAT 甲级 1046 Shortest Distance (20 分)(前缀和,想了一会儿)
1046 Shortest Distance (20 分) The task is really simple: given N exits on a highway which forms a ...
- PAT 甲级 1042 Shuffling Machine (20 分)(简单题)
1042 Shuffling Machine (20 分) Shuffling is a procedure used to randomize a deck of playing cards. ...
- PAT 甲级 1041 Be Unique (20 分)(简单,一遍过)
1041 Be Unique (20 分) Being unique is so important to people on Mars that even their lottery is de ...
- PAT甲级——A1152 GoogleRecruitment【20】
In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...
- PAT甲级——A1148 WerewolfSimpleVersion【20】
Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and th ...
随机推荐
- const 命令
const 命令声明一个只读的常量,声明后值不可以改变 const 变量不可以重复声明 const一旦声明变量,就必须立即初始化,不能留到以后赋值. const命令声明的常量也是不提升,同样存在暂时性 ...
- quartz的使用(二.基本过程)
1.关于各个要素的创建,SchedulerFactoryBean,CronTriggerFactoryBean及JobDetailFactoryBean全部实现spring中的FactoryBean& ...
- 关于a标签的href属性值的区别
一.href="javacript:;" 这种用法不正确,这么用的话会出现浏览器访问“javascript:;”这个地址的现象: 二.href="javacript:v ...
- bzoj1045题解
[解题思路] (数据范围劝退?正确范围应该是n≤1000000) 设xi表示第i个小朋友给第i+1个小朋友的糖果数(特殊的,xn表示第n个小朋友给第1个小朋友的糖果数),Â表示平均糖果数,有如下方程组 ...
- 探索NDIS HOOK新的实现方法(1)
NDIS HOOK是专业级防火墙使用的一种拦截技术,NDIS HOOK的重点是如何获得特定协议对应NDIS_PROTOCOL_BLOCK指针,获得了该指针,接下来就可以替换该协议所注册的收发函数,而达 ...
- ionic-CSS:ionic tab(选项卡)
ylbtech-ionic-CSS:ionic tab(选项卡) 1.返回顶部 1. ionic tab(选项卡) ionic tab(选项卡) 是水平排列的按钮或者链接,用以页面间导航的切换.它可以 ...
- LeetCode 852. Peak Index in a Mountain Array (山脉数组的峰顶索引)
题目标签:Binary Search 题目给了我们一组 int array,让我们找到数组的 peak. 利用 binary search, 如果数字比它后面那个数字小,说明还在上坡,缩小范围到右半边 ...
- Openstack Nova 源码分析 — Create instances (nova-conductor阶段)
目录 目录 前言 Instance Flavor Instance Status Virt Driver Resource Tracker nova-conductor Create Instance ...
- Oracle 生成sys_guid
select sys_guid() from dual;select sys_guid() from dual connect by rownum<100
- RTC, Real Time Clock
配置 写入RTC_PRL, RTC_CNT, RTC_ALR寄存器时,需要先进入配置模式,通过把RTC_CRL寄存器的CNF位置一. 另外,在每次配置一个寄存器时必须等待上一次配置完成,可以通过检测R ...