Source:

PAT A1120 Friend Numbers (20 分)

Description:

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

Keys:

  • 简单模拟

Code:

 /*
Data: 2019-08-14 16:21:28
Problem: PAT_A1120#Friend Numbers
AC: 13:24 题目大意:
数字的各位和称为朋友ID,求有多少个朋友ID
*/
#include<cstdio>
#include<set>
#include<string>
#include<iostream>
using namespace std; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n,cnt=;
string s;
set<int> st;
scanf("%d", &n);
for(int i=; i<n; i++)
{
cin >> s;
cnt=;
for(int j=; j<s.size(); j++)
cnt += s[j]-'';
st.insert(cnt);
}
cnt=;
printf("%d\n", st.size());
for(auto it=st.begin(); it!=st.end(); it++)
printf("%d%c", *it,++cnt==st.size()?'\n':' '); return ;
}

最新文章

  1. PHP设计模式(八)桥接模式(Bridge For PHP)
  2. maven File encoding has not been set
  3. [转载]How To Add Swap on Ubuntu 12.04
  4. 探秘重编译(Recompilations)(1/2)
  5. DOS常用的简单命令
  6. PHP抓取采集类snoopy介绍
  7. 【疯狂Java学习笔记】【第一章:Java语言概述】
  8. 关于View Link
  9. eclipse中Maven项目pom.xml报错:com.thoughtworks.xstream.io.HierarchicalStreamDriver
  10. DirectX11 With Windows SDK--26 计算着色器:入门
  11. SSM--spring框架
  12. Oracle pivot行转列函数案例
  13. python MD5加密方法
  14. ASP.NET AJAX入门系列
  15. ACM数论之旅2---快速幂,快速求a^b((ノ`Д&#180;)ノ做人就要坚持不懈)
  16. 浅谈JavaScript框架设计
  17. angular.js 中的作用域 数据模型 控制器
  18. ECharts概念学习系列之ECharts的下载和安装(图文详解)
  19. 异常: error MSB8008: 指定的平台工具集(V120)未安装或无效
  20. Linux 查看文件夹命令

热门文章

  1. HDU 1561&amp;HDU 3449 一类简单依赖背包问题
  2. HDU 1171 Big Event in HDU(01背包)
  3. 深入剖析Android四大组件(一)——Activity生命周期具体解释
  4. hdu 4941 Magical Forest (map容器)
  5. iOS-UIWebview比例缩放
  6. Spring+Mybatis之登录功能demo
  7. 无损压缩算法历史——熵编码是最早出现的,后来才有Lzx这些压缩算法
  8. POJ 3264 Balanced Lineup (线段树)
  9. 【BZOJ 1590】 Secret Message
  10. leetcode数组相关