题目
思路
用string来记录数字的输入,并相加求各位和;用散列hash【num】来判断朋友号是否出现;
AC代码
#include<bits/stdc++.h>
using namespace std
;
int main(){
int n
; cin
>>n
;
string s
;
bool hash
[10001]={0};
int num
=0;
int a
[1000]={0},cnt
=0;
for(int i
=0;i
<n
;i
++){
cin
>>s
;
for(int j
=0;j
<s
.length();j
++){
num
+=s
[j
]-'0';
}
if(hash
[num
]==0) {
a
[cnt
++]=num
;
hash
[num
]=1;
}
num
=0;
}
cout
<<cnt
<<endl
;
sort(a
,a
+cnt
);
for(int i
=0;i
<cnt
;i
++) {
if(i
!=cnt
-1) cout
<<a
[i
]<<' ';
else cout
<<a
[i
];
}
return 0;
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-12776.html