字符个数统计/华为机试

版权声明:本文为博主原创文章,转载请注明出处 https://blog.csdn.net/thecentry。 https://blog.csdn.net/thecentry/article/details/82192931

使用了查找表

描述

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

输入描述:

输入N个字符,字符在ACSII码范围内。

输出描述:

输出范围在(0~127)字符的个数。

示例1

输入

abc

输出

3

代码:

//第十题字符个数统计
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string str;
	getline(cin, str);
	int iMax = str.length();
	int table[128]{ 0 };
	int iCount = 0;
	for (int i = 0; i < iMax; i++)
	{
		
			if (table[str.at(i)])
			{
				continue;
			}
			else
			{
                table[str.at(i)]=1;
				iCount += 1;
			}
	}
	cout << iCount << endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/thecentry/article/details/82192931