来源:牛客网 字符个数统计
题目描述
编写一个函数,计算字符串中含有的不同字符的个数。字符在ACSII码范围内(0~127)。不在范围内的不作统计。
输入描述:
输入N个字符,字符在ACSII码范围内。
输出描述:
输出范围在(0~127)字符的个数。
输入例子:
abc
输出例子:
3
参考代码
#include <iostream>
#include <string.h>
using namespace std;
char str[10000];
int a[200];
int main(){
cin.getline(str,10000);
memset(a,0,sizeof(a));
for (int i=0;str[i];i++){
if (0<=str[i] && str[i]<=127)
a[str[i]]++;
}
int ans=0;
for (int i=0;i<128;i++)
if (a[i])
ans++;
cout<<ans<<endl;
return 0;
}