第一个出现一次的字符

来源:互联网 发布:城市综合治理大数据 编辑:程序博客网 时间:2024/06/05 20:58
#include <iostream.h>

#include <string.h>

char FirstNotRepeatingChar(char* pString)
{
      if(!pString)
            return 0;
      const int tableSize = 256;
      unsigned int hashTable[tableSize];
      for(unsigned int i = 0; i < tableSize; ++ i)
            hashTable[i] = 0;
      char* pHashKey = pString;
      while(*(pHashKey) != '\0')
            hashTable[*(pHashKey++)] ++;
      pHashKey = pString;
      while(*pHashKey != '/0')
      {
            if(hashTable[*pHashKey] == 1)
                 break;//return *pHashKey;

            pHashKey++;
      }
      return *pHashKey;
}

int main()
{
    cout<<"请输入一串字符:"<<endl;
    char s[100];
    cin>>s;
    char* ps=s;
    cout<<FirstNotRepeatingChar(ps)<<endl;
    return 0;
}
0 0
原创粉丝点击