描述
找出字符串中第一个只出现一次的字符
输入描述:
输入几个非空字符串
输出描述:
输出第一个只出现一次的字符,如果不存在输出-1
示例1
输入:
asdfasdfo
aabb
输出:
o
-1
#include <stdio.h>
#include <string.h>
int main(void)
{
char str[512] = {0};
int cnt[128] = {0};
int i, j, k, m;
int flag;
k = 0;
while(scanf("%s", str) != EOF)
{
flag = 0;
for(i=0; i<strlen(str); i++)
{
m = 0;
for(j=0; j<strlen(str); j++)
{
if(str[i] == str[j])
{
m++;
}
}
if(m == 1)
{
flag = 1;
cnt[k] = str[i];
break;
}
}
if(flag == 0)
{
cnt[k] = -1;
}
k++;
}
for(i=0; i<k; i++)
{
if(cnt[i] == -1)
{
printf("-1\n");
}
else
{
printf("%c\n", cnt[i]);
}
}
return 0;
}