PAT_A1120#Friend Numbers
Source:
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 ;
- }
PAT_A1120#Friend Numbers的更多相关文章
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- [LeetCode] Valid Phone Numbers 验证电话号码
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...
- [LeetCode] Consecutive Numbers 连续的数字
Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...
- [LeetCode] Compare Version Numbers 版本比较
Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 &l ...
随机推荐
- [poj2417]Discrete Logging_BSGS
Discrete Logging poj-2417 题目大意:求$a^x\equiv b(mod\qquad c)$ 注释:O(分块可过) 想法:介绍一种算法BSGS(Baby-Step Giant- ...
- Spring MVC-表单(Form)标签-单选按钮集合(RadioButtons)示例(转载实践)
以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_radiobuttons.htm 说明:示例基于Spring MVC 4.1.6. ...
- but no declaration can be found for element 'aop:aspectj-autoproxy'.
1.错误描写叙述 Multiple annotations found at this line: - cvc-complex-type.2.4.c: The matching wildcard is ...
- java wait 与 notify sleep
来自:http://blog.csdn.net/zyplus/article/details/6672775 有适当的代码修改. 在JAVA中,是没有类似于PV操作.进程互斥等相关的方法的.JAVA的 ...
- 使用OpenCV滑动条写成的简单调色器,实时输出RGB值
好久没有写博客了,近期在看OpenCV.于是动手写了个简单的RGB调色器,在终端实时输出RGB的值.通过这个程序学习滑动条的使用.程序中主要用到cvCreateTrackbar ,其使用方法例如以下: ...
- Windows热键注册的底层原理
要像系统注册一个全局热键,需要用到RegisterHotKey,函数用法如下(MSDN):BOOL RegisterHotKey( ...
- Git 少用 Pull 多用 Fetch 和 Merge 【已翻译100%】【转】
本文转载自:https://www.oschina.net/translate/git-fetch-and-merge?lang=chs&page=1# 本文有点长而且有点乱,但就像Mark ...
- etcd数据备份与恢复验证
一.单机 说明:执行etcd备份数据的恢复的机器必须和原先etcd所在机器一致 1.单机备份 etcdctl --endpoints="https://10.25.72.62:2379&qu ...
- codevs2596 售货员的难题(状压dp)
2596 售货员的难题 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 钻石 Diamond 题目描述 Description 某乡有n个村庄(1<n<=15 ...
- go之变量、指针、引用地址
一.值类型 定义和说明 定义:变量直接指向存在内存中的值,我们称之为值类型. 值类型的变量的值存储在栈中. 值类型 将一个变量赋值给另一个变量 被称为值拷贝 实例 package main impor ...