一、题目
二、个人理解
Tips:
- 本题实质就是在考怎么求各位数字和
- 另外证号一定小于40,所以可以采用数组保存
C++:
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int result[40];
for (int i = 0; i < 40; i++) {
result[i] = 0;
}
for (int i = 0; i < n; i++) {
int number, sum = 0;
cin >> number;
int temp = number;
while (number != 0) {//求各位数字和
sum += number % 10;
number /= 10;
}
result[sum] = temp;
}
int count = 0;//计数
for (int i = 0; i < 40; i++) {
if (result[i] != 0) {
count++;
}
}
cout << count << endl;
int tag = 1;//格式化输出
for (int i = 0; i < 40; i++) {
if (result[i] != 0) {
if (tag ) {
cout << i;
tag = 0;
} else {
cout << " " << i;
}
}
}
}