题解 | #找出字符串中第一个只出现一次的字符#
找出字符串中第一个只出现一次的字符
https://www.nowcoder.com/practice/e896d0f82f1246a3aa7b232ce38029d4
#include <stdio.h> int main() { char str[1001] ,b; int i=0,j=0,o=0,a=0,num=0; while (scanf("%s", str) != EOF) { // 注意 while 处理多个 case // 64 位输出请用 printf("%lld") to num=strlen(str); for(i=0;i<num;i++) { o=0; for(j=0;j<num;j++) { if(str[i]==str[j]&&i!=j) { o=1; break; } } if(o==0) { a=i; break; } } b=str[a]; } if(o==1) printf("-1"); else printf("%c\n", b); return 0; }