题解 | 字母统计
字母统计
https://www.nowcoder.com/practice/de7bf0945c1c4bd1aa9d49573b831f3c
#include <stdio.h> #include <string.h> using namespace std; int main(){ char arr[100];//数组的最大长度 scanf("%s",arr) ;//单独使用数组名就是内存地址(指针 int len=strlen(arr);//获取数组实际长度 int num; int count[91]={0};//用于记录每个字母出现的次数 //注:ASCLL码A~Z对应65~90 for(int i=65;i<=90;i++) { for(int j=0;j<len;j++){ num=arr[j];//将字母转化为数字 if(num==i) { count[i]++; } } } for(int i=65;i<=90;i++){ printf("%c:%d\n",i,count[i]); } return 0; }