mcz123321 @ 2024-03-13 21:31:57
#include<bits/stdc++.h>
using namespace std;
int main()
{
char a[1105];
long long b[200]={0},c;
cin>>a;
for(int i=0;i<strlen(a);i++)
{
c=a[i];
b[c]++;
}
c=-1;
for(int i=0;i<200;i++)
{
if(b[i]==1)
{
c=i;
break;
}
}
if(c==-1)
{
cout<<"no";
}
else
{
cout<<(char)c;
}
return 0;
}
by Douglas_MacArthur @ 2024-03-13 21:35:51
应该是遍历字符串而不是遍历ascii码
by StarRoam @ 2024-03-13 21:37:30
#include<bits/stdc++.h>
using namespace std;
int main()
{
char a[1105];
long long b[200]={0};
char c;
cin>>a;
for(int i=0;i<strlen(a);i++)
{
c=a[i];
b[c]++;
}
c=-1;
for(int i=0;i<strlen(a);i++)
{
if(b[a[i]]==1)
{
c=a[i];
break;
}
}
if(c==-1)
{
cout<<"no";
}
else
{
cout<<c;
}
return 0;
}
by StarRoam @ 2024-03-13 21:41:36
并且出现的第一次是字符串里的字符位置,不是字典序
by xk2013 @ 2024-03-13 21:47:16
@mcz123321