第一个只出现一次的字符

来源:互联网 发布:易语言远控源码2016 编辑:程序博客网 时间:2024/05/21 16:23

题目:在字符串中找出第一个只出现一次的字符。如输入“abaccdeff”,则输出’b‘。

char FirstNotRepeatingChar(char* pString);bool InvalidInput = false;char FirstNotRepeatingChar(char* pString){if (pString == NULL){InvalidInput = true;return 0;}unsigned int HashTable[256];int i=0;while (i < 256){HashTable[i++] = 0;}char *pIndexStr = pString;while ( *pIndexStr != '\0'){HashTable[*(pIndexStr++)]++;}pIndexStr = pString;while (*pIndexStr != '\0'){if (HashTable[*pIndexStr] == 1)break;pIndexStr++;}return *pIndexStr;}void test(){char TestStr[] = "aacddfhji";printf("FirstNotRepeatingChar Result = %c\n",FirstNotRepeatingChar(TestStr));}int _tmain(int argc, _TCHAR* argv[]){test();return 0;}


0 0