国产探花免费观看_亚洲丰满少妇自慰呻吟_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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永宁县| 高州市| 措美县| 连州市| 镇坪县| 垦利县| 文昌市| 社会| 洛宁县| 景宁| 阿巴嘎旗| 宁强县| 察雅县| 水富县| 樟树市| 曲沃县| 册亨县| 比如县| 德阳市| 宜君县| 奎屯市| 格尔木市| 竹山县| 阿拉善右旗| 沾化县| 新沂市| 巫溪县| 江油市| 泰和县| 广丰县| 于都县| 霍林郭勒市| 江陵县| 武宁县| 盐边县| 大足县| 岳阳市| 保定市| 鹤庆县| 山阳县| 兖州市|