Dreams_Knight @ 2022-10-09 22:49:09
#include<bits/stdc++.h>
using namespace std;
int a[26];
int main(){
string s;
cin >> s;
int len = s.size();
for(int i = 0;i < len;i++){
a[s[i] - 'a']++;
}
for(int i = 0;i < len;i++){
if(a[s[i] - 'a'] == 1){
cout << s[i];
return 0;
}
else{
cout << "no";
return 0;
}
}
return 0;
}
by Time_Limit_Exceed @ 2022-10-09 23:10:21
@Dreams_Promise 判断完不能直接返回丶
by RE_Automation @ 2022-10-09 23:10:30
题意理解出错
第二个for循环的else应该扔到循环外
否则就是判断字符串的第一位是否只出现一次了
by RE_Automation @ 2022-10-09 23:12:07
#include<bits/stdc++.h>
using namespace std;
int a[26];
int main(){
string s;
cin >> s;
int len = s.size();
for(int i = 0;i < len;i++){
a[s[i] - 'a']++;
}
for(int i = 0;i < len;i++){
if(a[s[i] - 'a'] == 1){
cout << s[i];
return 0;
}
}
cout<<"no"<<endl;
return 0;
}
by RE_Automation @ 2022-10-09 23:12:32
这样就ok了
by Dreams_Knight @ 2022-10-10 22:51:43
谢谢各位大佬