1004779564bzbjj @ 2022-07-24 19:08:41
#include<bits/stdc++.h>
using namespace std;
int x[256];
string a;
int main(){
getline(cin,a);
int len=a.size();
for(int i=0;i<len;i++){
x[a[i]]++;
}
for(int i=1;i<=255;i++){
if(x[i]==1){
char c=i;
cout<<c<<endl;
return 0;
}
}
cout<<"no";
return 0;
}
by FiresonZ @ 2022-07-24 19:12:18
找的是在字符串里面第一次仅出现一次的字符
by FiresonZ @ 2022-07-24 19:13:54
一个简单的Hack
aaaaaacaaabaaa
by FiresonZ @ 2022-07-24 19:14:12
应该输出c而你是b
by 1004779564bzbjj @ 2022-07-24 19:17:34
@FiresonZ ooo
by Albert_Wei @ 2022-07-24 19:18:44
1.x[]赋值为0
2.getline()会读入换行符
3.见楼上
#include<bits/stdc++.h>
using namespace std;
int x[256] = {0};
string a;
int main(){
cin >> a;
int len=a.size();
for(int i=0;i<len;i++){
x[a[i]]++;
}
for(int i=0;i<len;i++){
if(x[a[i]]==1){
char c=a[i];
cout<<c<<endl;
return 0;
}
}
cout<<"no";
return 0;
}
过了