题解 | #字母统计#
字母统计
https://www.nowcoder.com/practice/de7bf0945c1c4bd1aa9d49573b831f3c
#include<cstdio> #include<string> using namespace std ; int main(){ int ASCA[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; int count[26] = {0}; char arr[100]; scanf("%s",arr); string buf = arr; int len1 = buf.size(); for(int i = 0 ; i < len1 ;++i){ for(int j = 0 ; j < 26 ;++j){ if(buf[i] == ASCA[j]){ ++count[j]; }else{ continue; } } } for(int i = 0 ; i < 26 ;++i){ printf("%c:%d\n",ASCA[i],count[i]); } }