题目描述:
若字符串str为'' sbdddsbfc'',则输出 f;
若字符串str为''aabbccdd'',则输出:字符串str中的字符都出现两次以上
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<malloc.h>
int find_first_char(char* str)
{
assert(str);
char * phash = (char *)malloc(sizeof(int ) *256); //不能是int类型
assert(phash);
memset(phash, 0 , 256);
int i = 0 ;
// 第一遍进行映射
while(str[i] !='\0')
{
phash[str[i]] ++;
i++;
}
//第二遍找到第一个唯一只出现一个的字母
i = 0;
while(str[i] !='\0')
{
if(phash[str[i]] == 1)
return i;
i++;
}
return 0;
}
int main( )
{
char a[ ] = "aabsbccdFCD";
int pos = find_first_char(a);
if( 0 != pos)
{
printf("%c\n",a[pos]);
}
else
printf("没有这样的字母!");
return 0;
}