题解 | #字符个数统计#
字符个数统计
https://www.nowcoder.com/practice/eb94f6a5b2ba49c6ac72d40b5ce95f50
每次只读取一个字符,转换为ASCII后,用ASCII数值作为hash的下标,出现过的对hash[]赋值为1。
#include<stdio.h>
int main()
{
int hash[128]={0};
char B;
int count =0;
while(scanf("%1c",&B)!=EOF){
int asc = (int)B;
if(hash[asc]!=1){
count++;
hash[asc]=1;
}
}
printf("%d",count-1);//需要去掉最后的回车键
}

查看14道真题和解析
基恩士成长空间 421人发布