题解 | #字符个数统计#
字符个数统计
https://www.nowcoder.com/practice/eb94f6a5b2ba49c6ac72d40b5ce95f50
#include <stdio.h> int main() { char a[500]=""; int arr[128]={0}; int count=0; while (scanf("%s", a) != EOF) { // 注意 while 处理多个 case //获取字符串以后 //遍历整个字符串判断,如果计算过,则在arr中对应下标写1 char *q=a; while (*q) { int num=(int)*q; if(arr[num]==0)//表示该字符未计算过 { count++; arr[num]=1;//改变标志 } q++; } printf("%d\n",count); } return 0; }