【oj1953】字符个数统计

来源:互联网 发布:fft算法c语言实现 编辑:程序博客网 时间:2024/05/16 04:48
<pre name="code" class="cpp">/****************************************************题目名称:字符个数统计题目序号:oj1953输入:字符串,ACSII码0~127输出:字符串中不同字符的个数****************************************************/#include<iostream>#include<string>using namespace std;int main(){char input[100];cin.getline(input,100);int cnt = 0;const int TableSize = 256;unsigned int hashTable[TableSize];//初始化哈希表for(int i = 0;i < TableSize; i++)hashTable[i] = 0;  char *pHashKey = input;int len = strlen(input);//把字符串用哈希表表示while(*pHashKey)  {for(int i = 0;i < len; i++){if((int)*pHashKey >= 0 && (int)*pHashKey <=127)  {  hashTable[*pHashKey] ++;}pHashKey ++;}}  //统计哈希表中值不为0的键个数,就是不同字符出现的个数 for(int i = 0;i < TableSize; i++) {  if(hashTable[i] != 0) cnt++; }    cout << cnt <<endl;system("pause");return 0;}


                                             
0 0
原创粉丝点击