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 ...
随机推荐
- golang搭建一个简单的web服务器
package main import ( "io/ioutil" "log" "net/http" ) func main() { htt ...
- Load_file 常用路径
load_file 常用路径 WINDOWS下: c:/boot.ini //查看系统版本 c:/windows/php.ini //php配置信息 c:/windows/my.ini //MYSQL ...
- input event兼容性
<div class="wrapper"> <p>keypress - event not call on adroid</p> <inp ...
- C语言:字符串拷贝(截取)、查找
C语言:字符串拷贝(截取).查找 很惭愧,学了这么久别的语言,一直没有好好学C和C++,所以现在开始认真C/C++的一些特性和比较,这里记录下C语言拷贝和截取的一些方式,由于系统库带的函数不方便,所以 ...
- 链接github
引用https://www.cnblogs.com/u-1596086/p/11588957.html 第一步:登录git创建项目 右上角头像按钮,点击your repositories 接着绿色按钮 ...
- python打包生成可执行文件教程
python打包生成可执行文件教程 安装环境: 1.打开命令行窗口,输入命令:pip install pyinstaller ,等待下载结束.示例: 2.下载结束后,测试是否成功安装,输入命令:pyi ...
- css选择器四大类:基本、组合、属性、伪类
什么是选择器?选择器的作用是通过它可以找到元素,把css样式传递给元素!css选择器主要分为:基本选择器.属性选择器.组合选择器与伪类选择器四个大类! css基本选择器 基本选择器又分为:*通配符.标 ...
- Resnet——深度残差网络(二)
基于上一篇resnet网络结构进行实战. 再来贴一下resnet的基本结构方便与代码进行对比 resnet的自定义类如下: import tensorflow as tf from tensorflo ...
- em和rem区别
em大小依据父元素的字体大小的倍数 rem大小依据与根元素,即html标签的font-size大小
- MATLAB应用专题part2-电力电子仿真技术
有匪君子,如切如磋,如琢如磨. --<诗经·卫风·淇奥> 这篇博客知识我记录一下我在仿真学习中积累到的知识和遇到的坑. 第一部分:知识部分 1.为什么电阻与电感串联电路中电流的波形比电压的 ...