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进行想打印存储,因为数据量不是很大,最后直接输出.但是还是觉得没有必要. 主要考虑两个问题,首先是数字转化为字符串,实质就是进制转化,但是有点不同,如果十位有数字,个 ...
随机推荐
- hibernate--DetachedCriteria(离线条件查询)
一.叙述 离线条件查询的好处,可以在非dao层封装查询参数,封装完成后,将对象传递到dao层,关联到session后,再去查询数据,这样做dao层可以极大的简化代码.下面通过一个小案例,一起来感受一下 ...
- 【vue】vue使用Element组件时v-for循环里的表单项验证方法
转载至:https://www.jb51.net/article/142750.htm标题描述看起来有些复杂,有vue,Element,又有表单验证,还有v-for循环?是不是有点乱?不过我相信开发中 ...
- 我的TDD实践---CI持续集成
“我的TDD实践”系列之CI持续集成 写在前面: 我的TDD实践这几篇文章主要是围绕测试驱动开发所展开的,其中涵盖了一小部分测试理论,更多的则是关注工具的使用及环境的搭建,做到简单实践先行,后理论专精 ...
- 重拾C++第一天_WDS
1.面向对象编程的三大特点:封装.继承.多态 2.C++中若不指定类中成员的访问权限默认就是private的(class默认是private的,struct默认是public的). 3.C++规范中类 ...
- NET使用NPOI组件导出Excel-入门示例及通用方法
一.Excel导入及导出问题产生: 从接触.net到现在一直在维护一个DataTable导出到Excel的类,时不时还会维护一个导入类.以下是时不时就会出现的问题: 导出问题: 如果是as ...
- oracle-闪回技术1
http://blog.csdn.net/lqx0405/article/details/44776737 Oracle Study案例之--基于表空间的时间点恢复(TSPITR) DBPITR 数 ...
- CSS如何实现”右部宽度固定,左部自适应“的布局
吃过晚饭后,开始刷前端笔试题,却遇到了一道CSS难题——使用CSS实现左部自适应.右部固定宽度为200px的布局.当时第一眼看到题目时,以为只是一道很简单的题目.不就是定义两个左浮动的div,右部的宽 ...
- MySQL之 从复制延迟问题排查
一.从库复制延迟问题 1.可能的原因如下(1)主从服务器处于不同的网络之中,由于网络延迟导致:(2)主从服务器的硬件配置不同,从服务器的硬件配置(包括内存,CPU,网卡等)远低于主服务器:(3)主库上 ...
- spring boot 项目 热启动
第一需要 spring-boot-devtools 依赖 <dependency> <groupId>org.springframework.boot</groupId& ...
- yii 分页查询
控制器 <?php namespace backend\controllers; use app\models\Comment; use app\models\Commentstatus; us ...