您的位置:首页 > 其它

字符个数统计

2016-01-07 20:07 239 查看


题目描述

编写一个函数,计算字符串中含有的不同字符的个数。字符在ACSII码范围内(0~127)。不在范围内的不作统计。

输入描述:
输入N个字符,字符在ACSII码范围内(0~127)。

输出描述:
输出字符的个数。

输入例子:
abc


输出例子:
3


<span style="font-size:14px;">#include <iostream>
#include <string>
using namespace std;

int main(){
string str;
int result;
int count = 0;
int a[130] = { 0 };
cin >> str;
int n = str.length();
for (int i = 0; i < n; i++){
if (a[str[i]] == 0){
count++;
a[str[i]] = 1;
}
}

cout << count << endl;
//system("pasue");
return 0;
}</span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: