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

#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;
char find(char * str)
{
    if(str==NULL)
        return '\0';
    int hash[256];
    for(int i=0;i<256;i++)
        hash[i]=0;
    char *hashKey=str;
    while(*hashKey!='\0')
        hash[*(hashKey++)]++;
    hashKey=str;
    while(*hashKey!='\0')
    {
        if(hash[*hashKey]==1)
            return *hashKey;
        hashKey++;

    }
}
int main()
{
    char* a="afefcdd";
    char res=find(a);
    cout<<res;
    system("pause");
}

posted @ 2015-09-18 21:05  小左手  阅读(117)  评论(0)    收藏  举报