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 ...
随机推荐
- 2014年辛星jquery解读第三节 Ajax
***************Ajax********************* 1.Ajax是Asynchronous Javascript And XML的简写,它指的是异步Javascript ...
- 微信小程序的小问题(1)
1. imgUrls: [ '../../images/index/banner1.jpg', '../../images/index/banner2.jpg', '../../images/inde ...
- Linux线程池在server上简单应用
一.问题描写叙述 如今以C/S架构为例.client向server端发送要查找的数字,server端启动线程中的线程进行对应的查询.将查询结果显示出来. 二.实现方案 1. 整个project以cli ...
- android在学习——activity关闭和dialog.dismiss冲突的解决(Activity has leaked window com.android.internal.policy.impl.PhoneWindow)
当我们在退出整个程序的时候偶尔会出现这种报错:Activity has leaked window com.android.internal.policy.impl.PhoneWindow 其意思大概 ...
- Android对话框与Activity共存时的异常
异常提示信息 01-01 18:30:38.630: E/WindowManager(14537): Activity com.jack.outstock.activity.ManageCustomA ...
- A Reusable Aspect for Memory Profiling
例子: malPro.acc文件: #include <stdlib.h> size_t totalMemoryAllocated; int totalAllocationFuncCall ...
- Newtonsoft.Json 序列化日期问题解决
上代码 其中的使用方法和UserInfo实体对象就不贴代码了. /// <summary> /// 把对象转成json字符串 /// </summary> /// <pa ...
- CSS实现列表li边框重合问题
CSS实现列表li边框重合问题 2017年04月13日 21:04:18 阅读数:5066 在我们写东西的时候经常要用到ul,但是也经常会出现li边框重合的问题,如下图: 可以看到每个格子的右边框和 ...
- Python 35 进程间的通信(IPC机制)、生产者消费者模型
一:进程间的通信(IPC):先进先出 管道:队列=管道+锁 from multiprocessing import Queue q=Queue(4) q.put(['first',],block=T ...
- C - New Year Candles
Problem description Vasily the Programmer loves romance, so this year he decided to illuminate his r ...