1,2,3,前三全wa

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

lucy2012 @ 2024-02-07 14:43:10

在此请大佬欣赏指点

#include<bits/stdc++.h>
using namespace std;
char ch[1101];
int main() {
    string s;
    getline(cin,s);
    for(int i=0;i<=s.length()-1;i++){
        for(int j=0;j<i;j++){
            if(s[i]==s[j]){
                ch[i]=' ';
                ch[j]=' ';
            }
        }
        if(ch[i]!=' ')
            ch[i]=s[i];
    }
    for(int i=0;i<=s.length();i++){
        if(ch[i]!=' '){
            cout<<ch[i];
            return 0;
        }
    }
    cout<<"no";
    return 0;
}

by chiken_beautiful @ 2024-02-07 14:51:06

这句for中,s.length()也要加-1

for(int i=0;i<=s.length();i++){
        if(ch[i]!=' '){
            cout<<ch[i];
            return 0;
        }
    }

by chiken_beautiful @ 2024-02-07 15:00:30

@lucy2012


by lucy2012 @ 2024-02-07 15:15:12

@chiken_beatiful 嗯!谢谢!


|