1 #include <iostream>
2 using namespace std;
3
4 char lmf(char *pString)
5 {
6 if(!pString)
7 {
8 return 0;
9 }
10 //定义并初始化hash表
11 unsigned int hash[256] = {0};
12
13 char *pHashKey = pString;
14 //根据字符串,计数!!!
15 while(*pHashKey != '\0')
16 {
17 hash[*pHashKey]++;
18 pHashKey++;
19 }
20 //复原
21 pHashKey = pString;
22 //再次遍历字符串,取得第一个只出现一次的字符
23 while(*pHashKey != '\0')
24 {
25 if(hash[*pHashKey] == 1)
26 {
27 return *pHashKey;
28 }
29 pHashKey++;
30 }
31 return 0;
32 }
33
34 void main()
35 {
36 char *a = "abbaccdeeffggh";
37 char ch = lmf(a);
38 putchar(ch);
39 }