国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

PAT甲級1120

2019-11-08 19:24:43
字體:
來源:轉載
供稿:網友

1120. Friend Numbers (20)

時間限制400 ms內存限制65536 kB代碼長度限制16000 B判題程序Standard作者CHEN, Yue

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 friend ID's among them. Note: a number is considered a friend of itself.

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:
8123 899 51 998 27 33 36 12Sample Output:
43 6 9 26
#include<iostream>#include<set>#include<string>#include<algorithm>using namespace std;int main(){	int N;	cin >> N;	string s;	set<int> st;	for (int i = 0; i < N; i++)	{		cin >> s;		int sum = 0;		for (int j = 0; j < s.size(); j++)		{			sum += s[j] - '0';		}		st.insert(sum);	}	cout << st.size() << endl;	for (set<int>::iterator it = st.begin(); it != st.end(); it++)	{		if (it == st.begin())		{			cout << *it;		}		else		{			cout << " " << *it;		}	}	return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 济南市| 桐梓县| 朔州市| 荆州市| 连平县| 海丰县| 招远市| 克东县| 沅陵县| 丹江口市| 家居| 射阳县| 白朗县| 汕头市| 铜鼓县| 乌苏市| 望谟县| 定南县| 东乡族自治县| 博兴县| 读书| 扶余县| 宁晋县| 扶沟县| 德令哈市| 唐海县| 象山县| 大渡口区| 正镶白旗| 建宁县| 广昌县| 饶阳县| 夏河县| 泌阳县| 道孚县| 宣武区| 濉溪县| 修水县| 利辛县| 永泰县| 寿阳县|