找到第一個只出現一次的字符

// 第一個只出現一次的字符.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;

}
相關文章
相關標籤/搜索