题解 | #字符个数统计#
字符个数统计
https://www.nowcoder.com/practice/eb94f6a5b2ba49c6ac72d40b5ce95f50
// 使用哈希记录是否出现 用ASCII记录 所以哈希的范围是 0-127
#include <stdio.h>
#include <string.h>
int main() {
char str[500]={0};
gets(str);
int hash[128]={0};
int n = 0;
//记录哈希
for(int i=0;i<strlen(str);i++)
{
int rehash = (int)str[i];
hash[rehash] = 1;
}
//遍历哈希
for(int i=0;i<128;i++)
{
if(hash[i]==1)
{
n++;
}
}
printf("%d\n",n);
return 0;
}
