#include <iostream> using namespace std; char lmf(char *pString) { if(!pString) { return 0; } //定义并初始化hash表 unsigned int hash[256] = {0}; char *pHashKey = pString; //根据字符串,计数!!! while(*pHashKey != '\0') { hash[*pHashKey]++; pHashKey++; } //复原 pHashKey = pString; //再次遍历字符串,取得第一个只出现一次的字符 while(*pHashKey != '\0') { if(hash[*pHashKey] == 1) { return *pHashKey; } pHashKey++; } return 0; } void main() { char *a = "abbaccdeeffggh"; char ch = lmf(a); putchar(ch); }