题目描述
编写一个函数,计算字符串中含有的不同字符的个数。字符在ACSII码范围内(0~127)。不在范围内的不作统计。
输入描述:
输入N个字符,字符在ACSII码范围内。
输出描述:
输出范围在(0~127)字符的个数。
输入例子:
abc
输出例子:
3
#include<iostream>
#include<string>
using namespace std;
int count(string c)
{
int temp[127]={0};
int count=0;
for(auto i:c)
temp[i-0]++;
for(int i=0;i<127;i++)
if(temp[i]!=0)
count++;
return count;
}
int main()
{
string str;
while(cin>>str)
{
for(auto i:str)
if(i<=1||i>=127)
continue;
cout<<count(str)<<endl;
}
return 0;
}