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 ...
随机推荐
- docker 命令操作
1.停止所有的container,这样才能够删除其中的images: docker stop $(docker ps -a -q) 如果想要删除所有container的话再加一个指令: docker ...
- win7在本地windows的hosts文件中,添加新的域名映射后,不生效(问题描述:hosts文件添加自定义域名后,ping 不通域名,但是ping ip可以)
将原来的hosts文件删除,在C:\Windows\System32\drivers\etc目录下,新建一个新的hosts文件(记住文件不要后缀,不要命名为.txt,本人在此踩过坑,或者可以百度搜索下 ...
- CentOS7-安装最新版本GIT(git version 2.18.0)
Git安装方式有两种一种是yum安装一种是编译安装: 一.yum命令安装,此方法简单,会自动安装依赖的包,而且会从源里安装最新的版本,如果仓库不是最新的话安装的也不是最新Git. sudo yum i ...
- NX二次开发-如何在类外面定义一个结构体
#include <uf.h> #include <uf_obj.h> #include <uf_part.h> using namespace NXOpen; u ...
- ionic:temple
ylbtech-ionic:temple 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 6.返回顶部 作者:ylbtech出处:http://ylb ...
- Putty 两步代理访问互联网
工作在机房,有时需要访问外网. 此时浏览器需要使用代理服务器,访问的流程如下: 由于SERVER2不能直接访问互联网,而SERVER3可以(机房无法直接访问SERVER3)所以需要两步代理. 配置流程 ...
- 引入css文件时,css link和@import区别
这里link与@import介绍的是html引入css的语法单词.两者均是引入css到html的单词. 一.了解基本 1.link语法结构 <link href="CSSurl路径&q ...
- IDEA @Autowired dao大红波浪线
SptingBoot+Mybatis开发通常在dao层的注解是@Mapper 这样每次在ServiceImpl层加注解@Autowired时,注入的dao总是波浪线烦人,其实并没有错,只是idea你太 ...
- SparkListener监听使用方式及自定义的事件处理动作
本文针对spark 2.0+版本 概述 spark 提供了一系列整个任务生命周期中各个阶段变化的事件监听机制,通过这一机制可以在任务的各个阶段做一些自定义的各种动作.SparkListener便是这些 ...
- vue axios springBoot 跨域session丢失
前端: 在引入axios的地方配置 axios.defaults.withCredentials=true,就可以允许跨域携带cookie信息了,这样每次发送ajax请求后,只要不关闭浏览器,得到的s ...