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

// 第一个只出现一次的字符.cpp : 定义控制台应用程序的入口点。

//

#include "stdafx.h"

#include<iostream>

using namespace std;

void FirstNotRepeatChar(char *a)

{

 if(a == NULL)

  return;

 int hashTable[256]={0};

 char *p = a;

 while(*p){

  hashTable[*(p++)]++;}

 p=a;

 while(*p)

 {

  if(hashTable[*p]==1)

  {

   cout<<*p;return;

  }

  p++;

 }

}

int main()

{

 char *a="ababccdeff";

 FirstNotRepeatChar(a);

 system("pause");

 return 0;

}
相关文章
相关标签/搜索