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 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
set的基础用法 找出不同的元素 计算集合的个数以及遍历集合
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
int a[];
int _deal(int x)
{
int sum=;;
while(x){
sum+=x%;
x/=;
}
return sum;
}
int main()
{
int n;
while(cin>>n){
set<int> s;
set<int> ::iterator ite;
for(int i=;i<n;i++){
cin>>a[i];
s.insert(_deal(a[i]));
}
cout<<s.size()<<endl;
for(ite=s.begin();ite!=s.end();ite++){
if(ite==s.begin()) cout<<*ite;
else cout<<" "<<*ite;
}
cout<<endl;
}
return ;
}
PAT (Advanced Level) Practice 1120 Friend Numbers (20 分) (set)的更多相关文章
- PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642
PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...
- PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642
PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...
- PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642
PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642 题目描述: Being unique is so important to peo ...
- PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642
PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642 题目描述: A reversible prime in any n ...
- PAT (Advanced Level) Practice 1152 Google Recruitment (20 分)
In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...
- PAT (Advanced Level) Practice 1015 Reversible Primes (20 分)
A reversible prime in any number system is a prime whose "reverse" in that number system i ...
- PAT (Advanced Level) Practice 1028 List Sorting (25 分) (自定义排序)
Excel can sort records according to any column. Now you are supposed to imitate this function. Input ...
- 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 (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642
PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642 题目描述: People in Mars represent the c ...
随机推荐
- 手写-- K-means++
1. K-means++原理 K均值聚类属于启发式方法,不能保证收敛到全局最优,初始中心的选择会直接影响聚类结果.K-means是随机选择样本点作为聚类中心,容易造成算法局部收敛或者需要较多迭代次数, ...
- 【转载】SPI总线和I2C总线的异同点
来源:https://blog.csdn.net/lishun1422840684/article/details/77776763 总结的简单.明了.适用! 一:SPI接口的全称是"Ser ...
- 论文翻译:2015_DNN-Based Speech Bandwidth Expansion and Its Application to Adding High-Frequency Missing Features for Automatic Speech Recognition of Narrowband Speech
论文地址:基于DNN的语音带宽扩展及其在窄带语音自动识别中加入高频缺失特征的应用 论文代码:github 博客作者:凌逆战 博客地址:https://www.cnblogs.com/LXP-Never ...
- JavaScript——基础知识,开始我们的js编程之旅吧!
JavaScript基础第01天 1. 编程语言 编程语言: 可以通过类似于人类语言的"语言"来控制计算机,让计算机为我们做事情,这样的语言就叫做编程语言(Programming ...
- Shiro -- (四) 数据库支持
主要就是JdbcRealm这个类 先看一下部分源码: 先建表:users(用户名 / 密码).user_roles(用户 / 角色).roles_permissions(角色 / 权限),并且往use ...
- MySQL之ERROR 1558 (HY000): Column count of mysql.user is wrong.解决方案
一.场景 我本想在MySQL5.7上执行下列语句创建一个新用户: CREATE USER "remote"@"%" IDENTIFIED BY "12 ...
- js是什么?js可以做什么?js的构成与学习方向
js(百度官方介绍javascript)编程的基本语言学习目标是:a.怎么写和运行js脚本b.理解变量和值c.学会简单的数学运算符d.数据类型是什么e.流程控制 对于JavaScript的背景知识和结 ...
- Android 日期选择框 简洁常用
效果 核心代码 >方法 /** * @description 选择日期弹出框 * @param listener 选择日期确定后执行的接口 * @param curDate 当前显示的日期 * ...
- python实现串口通讯小程序(GUI界面)
python实现串口通讯小程序(GUI界面) 使用python实现串口通讯需要使用python的pyserial库来实现,这个库在安装python的时候没有自动进行安装,需要自己进行安装. 1.安装p ...
- 消息队列(三)Apache ActiveMQ
在Ubuntu上安装ActiveMQ 系统初始化 $ sudo apt update $ sudo apt dist-upgrade $ sudo apt autoremove $ sudo apt ...