题解 | #字符个数统计#
字符个数统计
https://www.nowcoder.com/practice/eb94f6a5b2ba49c6ac72d40b5ce95f50
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main() {
int a;
int i,j,k=0;
char str[500];
scanf("%s",str);
a=strlen(str);
for(i=0;i<=127;i++)
{
for(j=0;j<a;j++)
{
if(i==str[j])
{
k++;
break;
}
}
}
printf("%d",k);
return 0;
}
该题目要求找出输入的字符串的不同字符个数,且字符串的范围须在ASICII表内的0~127范围内,因此我们可以将这0~127共128个不同字符作为外循环的变量,而这输入的字符串包含的每一个字符作为内循环变量,按照这样的思路,运用到两个循环,就能找出不同字符个数并输出。
#牛客创作赏金赛#