题目要求*
小M最近迷上了字符串,每看到一个新字符串,他都想知道字符串中有多少个不同的字符。
现在,请你帮助小M解决这个问题。
Input
多组输入,每组只有一行,这行只有一个字符串。保证字符串中,只有小写字母,字符串的长度大于0不超过1000。
Output
对于每组,输出一个数字,表示字符串中有多少个不同字符。
Sample Input
Raw
abcdefg
bbbbbbbb
hfksdhf
Sample Output
Raw
7
1
5
字符串的相关问题
小写字母可以ascall来表示 a=97以此类推。
只要每个输入字符与之前的遍历比较就可以了
#include<stdio.h>
#include<string.h>
#define MAX 1000
using namespace std;
int main()
{
char num[128]={0};
char str[1000]={0};
while(fgets(str,MAX,stdin))
{
int count = 0,len,i;
len = strlen(str);
for(i = 0;i < len - 1;i ++)
{
if(str[i] >= 0 && str[i] <= 127)
num[str[i]]++;
}
for(i = 0;i < 127;i ++)
{
if(num[i] != 0)
count++;
}
printf("%d\n",count);
memset(num,0,sizeof(num));#记得要清除数组
memset(str,0,sizeof(str));
}
return 0;
}```