/******************************************** * 在一个字符串中找到第一个只出现一次的字符。如输入abaccdeff,则输出b *********************************************/ #include <stdio.h> #include <string.h> #define N 256 int charHash[N] = {0}; void initCharHash(const char *s) { while(*s) { charHash[*s]++; s++; } } char findFirstOnceChar(const char *s) { while(*s) { if(charHash[*s] == 1) { return *s; } s++; } return 0; } int main(void) { char *str = "abaccdeff"; initCharHash(str); printf("%c\n",findFirstOnceChar(str)); return 0; } /********* b Process returned 0 (0x0) execution time : 1.254 s Press any key to continue. **********/