#include <stdio.h>
#include <iostream.h>
//find the first letter which one appear once
//input abacddaef, the reture should be 'b'
char * findLetter(char * str)
{
int hashTable[256] = {0};
if (str == NULL)
return NULL;
char *p;;
for (p = str; *p != '\0'; p++)
hashTable[*p]++;
for (p = str; *p != '\0'; p++)
{
if (hashTable[*p] == 1)
return p;
}
return NULL;
}
void main(void)
{
char str[100];
printf("please input the string:\n");
scanf("%s", str);
char * p = findLetter(str);
if (p!= NULL)
printf("IT IS: %c\n", *p);
else
printf("can't find it!\n");
}
第一个只出现一次的字符
最新推荐文章于 2021-02-10 13:26:47 发布