题解 | #找出字符串中第一个只出现一次的字符#
找出字符串中第一个只出现一次的字符
http://www.nowcoder.com/practice/e896d0f82f1246a3aa7b232ce38029d4
#include<stdio.h>
#include<string.h>
#define SIZE 1001
int main()
{
char a[SIZE];
int i = 0, j = 0,cnt = 0, k = 0;
int x = 0;
while(scanf("%s",a) != EOF){
// x = strlen(a);
for(i = 0; i<strlen(a);i++){
for(j =0; j <strlen(a);j++){
if(a[i] == a[j])
cnt++;
else
continue;
}
if(cnt == 1 && k == 0){
printf("%c\n",a[i]);
k++;
}
else
cnt = 0;
}
if(k == 0)
printf("-1\n");
else
k = 0;
}
return 0;
}
#include<string.h>
#define SIZE 1001
int main()
{
char a[SIZE];
int i = 0, j = 0,cnt = 0, k = 0;
int x = 0;
while(scanf("%s",a) != EOF){
// x = strlen(a);
for(i = 0; i<strlen(a);i++){
for(j =0; j <strlen(a);j++){
if(a[i] == a[j])
cnt++;
else
continue;
}
if(cnt == 1 && k == 0){
printf("%c\n",a[i]);
k++;
}
else
cnt = 0;
}
if(k == 0)
printf("-1\n");
else
k = 0;
}
return 0;
}