题意:略。
思路:水题,略。
代码:
#include <iostream> #include <string> using namespace std; const int N=50; int cnt[N]={0}; int main() { int n; string str; cin>>n; while(n--){ cin>>str; int sum=0; for(auto ch:str) sum+=ch-'0'; cnt[sum]++; } int len=0; for(int i=0;i<N;i++) if(cnt[i]!=0) len++; cout<<len<<"\n"; int m=0; for(int i=0;i<N;i++){ if(cnt[i]!=0){ cout<<i; m++; if(m<len) cout<<" "; } } return 0; }
本文介绍了一个简单的计数问题,并提供了一种通过读取输入字符串并统计特定数值出现次数的方法来解决该问题。代码实现使用了C++语言,通过遍历字符串计算每个字符串中数字的总和,并将这些总和存储在一个计数数组中,最终输出所有非零计数的项。
419

被折叠的 条评论
为什么被折叠?



