【GESP三级】字符统计暂无标签时间限制:CC++ 1000MS其他语言 2000MS内存限制:CC++ 16MB其他语言 32MB难度:中等出题人:描述输入一串小写字母以‘’为结束标志统计出每个字母在该字符串中出现的次数若某字母不出现则不要输出。 要求:每行输出5项每项以空格隔开。输入描述输入一行以’结束的字符串输出描述输出相应小写字母的个数。用例输入 1 aaaabbbccc用例输出 1 a4
#include
int main() { string str; getline(cin, str);
unordered_map<char, int> count;
for(int i=0; i<str.length(); i++)
{
char c = str[i];
if(c == '.')
break;
count[c]++;
}
int cnt = 0;
for(auto it=count.begin(); it!=count.end(); it++)
{
cout << it->first << ":" << it->second << " ";
cnt++;
if(cnt % 5 == 0)
cout << endl;
}
return 0;
}
原文地址: http://www.cveoy.top/t/topic/i7rf 著作权归作者所有。请勿转载和采集!