70分求助,样例全过

B2110 找第一个只出现一次的字符

Cokewithice @ 2021-12-26 16:49:32


#include<bits/stdc++.h>
using namespace std;
map <char,int> a;string n;
int main(){
cin>>n;
for(int i=0;i<=n.size();i++)a[n[i]]++;
for(int i=0;i<=n.size();i++)
{if(a[n[i]]==1){cout<<n[i];return 0;}}
cout<<"no";return 0;}

by Cokewithice @ 2021-12-26 16:49:54

在线等


by Lucky_M @ 2021-12-26 17:05:33

你这写的,我竟没看懂。。


by Lucky_M @ 2021-12-26 17:07:14

#include<bits/stdc++.h>
using namespace std;
int vis[114514];
string ch;
int main(){
    cin>>ch;
    for(int i=0;i<ch.size();i++){
        vis[ch[i]-'a'+1]++;                
    }
    for(int i=0;i<ch.size();i++){
        if(vis[ch[i]-'a'+1]==1){
            printf("%c",ch[i]);
            return 0;
        }
    }
    printf("no");
    return 0;
}

这是我的代码,可参考


by Lucky_M @ 2021-12-26 17:07:34

@15LIHONGJIAN


by Cokewithice @ 2021-12-26 17:14:32

好的,谢谢


by _RedForest @ 2021-12-26 17:31:19

i<n.size()


|