找字符串中第一个只出现一次的字符

来源:互联网 发布:unity3d litjson 编辑:程序博客网 时间:2024/05/17 07:44
#include<iostream>#include<stdio.h>char  find_fir_repeat_char(const char *str);char  find_fir_repeat_char(const char *str){    if(NULL == str)    {        return '\0';    }    const char *p_str  =NULL;    int count[256] = {0};    for(p_str = str; *p_str != '\0';p_str++)    {        count[*p_str]++;    }    p_str = str;    while(p_str != '\0'){         if(count[*p_str] == 2)         {             return *p_str;         }         p_str++;    }} int main(){    char str[] = "liusenin";   char cha = find_fir_repeat_char(str);    printf("%c\n",cha);    return 0;}

运行结果:

i
Press any key to continue

小结:
哈希表的思想

0 0