70分求助

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

IaLWH @ 2021-08-18 20:58:31

#include<stdio.h>
#include<cstring>
#include<vector>
using namespace std;
int main(){
    char s[1101];
    vector<char>a;
    vector<char>::iterator it;
    int i,p=0,j;
    scanf("%s",s);
    for(i=0;i<strlen(s);i++){
        p=a.size();
        for(it=a.begin();it<a.end();it++)
            if(s[i]==*it)a.erase(it);
        if(p==a.size())a.push_back(s[i]);
    }
    if(a.empty()){
        printf("no");
        return 0;
    }
    printf("%c",a[0]);
    return 0;
}

样例全过,提交70分,用vector解


by IaLWH @ 2021-08-18 21:03:45

在线等ing......


by InterN_NOT_FOUND @ 2021-08-18 21:12:47

@PluckDuck 我来了


by InterN_NOT_FOUND @ 2021-08-18 21:14:46

@PluckDuck 不是吧,b库的红题用stl


by IaLWH @ 2021-08-18 21:24:43

@TOTGOD 我真TM爱你


by InterN_NOT_FOUND @ 2021-08-18 21:32:56

@PluckDuck 我也TM爱你

#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 InterN_NOT_FOUND @ 2021-08-18 21:33:19

@PluckDuck


|