题解 | 找出字符串中第一个只出现一次的字符
找出字符串中第一个只出现一次的字符
https://www.nowcoder.com/practice/e896d0f82f1246a3aa7b232ce38029d4
#include <stdio.h>
#include <string.h>
int main() {
char str[1001];
scanf("%s",str);
int i,j;
int n = 0;
int len = strlen(str);
for(i=0;i<len;i++)
{
int k = 0;
int m = 0;
for(j=0;j<len;j++)
{
if(str[i] == str[j])
{
m++;
}
else if(str[i] != str[j]){
k++;
}
}
if(k == len -1 && m == 1)
{
n++;
printf("%c",str[i]);
break;
}
}
if(n == 0) printf("-1");
return 0;
}
360集团公司氛围 360人发布
查看19道真题和解析