题解 | #字母统计#
字母统计
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'}; char arr[200]; scanf("%s",arr); string buf = arr; arr[buf.size()-1] = '\0'; int count[26] = {0}; for(int i = 0 ;i < 26 ; ++ i){ for(int j = 0 ; j < buf.size() ; ++j) { if (ASCA[i] == buf[j]) { ++count[i]; } else { count[i] = count[i]; } } } for(int i= 0 ; i < 26; ++i) { printf("%c:%d\n", ASCA[i], count[i]); } }