C++80分求助!!!

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

answerking @ 2023-08-03 22:15:09

#include<iostream>
#include<string>
using namespace std;
int vis[26];
int main(){
    string a;
    cin>>a;
    for(int i=0;i<a.size();i++){
        vis[a[i]-'a']++;        
    }
    for(int i=0;i<26;i++){
        if(vis[i]==1){
            switch(i){
                case 0:cout<<"a"<<endl;return 0;
                case 1:cout<<"b"<<endl;return 0;
                case 2:cout<<"c"<<endl;return 0;
                case 3:cout<<"d"<<endl;return 0;
                case 4:cout<<"e"<<endl;return 0;
                case 5:cout<<"f"<<endl;return 0;
                case 6:cout<<"g"<<endl;return 0;
                case 7:cout<<"h"<<endl;return 0;
                case 8:cout<<"i"<<endl;return 0;
                case 9:cout<<"j"<<endl;return 0;
                case 10:cout<<"k"<<endl;return 0;
                case 11:cout<<"l"<<endl;return 0;
                case 12:cout<<"m"<<endl;return 0;
                case 13:cout<<"n"<<endl;return 0;
                case 14:cout<<"o"<<endl;return 0;
                case 15:cout<<"p"<<endl;return 0;
                case 16:cout<<"q"<<endl;return 0;
                case 17:cout<<"r"<<endl;return 0;
                case 18:cout<<"s"<<endl;return 0;
                case 19:cout<<"t"<<endl;return 0;
                case 20:cout<<"u"<<endl;return 0;
                case 21:cout<<"v"<<endl;return 0;
                case 22:cout<<"w"<<endl;return 0;
                case 23:cout<<"x"<<endl;return 0;
                case 24:cout<<"y"<<endl;return 0;
                case 25:cout<<"z"<<endl;return 0;
            }
        }
    }
    cout<<"no"<<endl;
    return 0;
} 

by wzb13958817049 @ 2023-08-03 22:45:04

@wjt20111219 rt,B2110 找第一个只出现一次的字符


by Weizhuo_Zhao @ 2023-08-03 23:19:51

@wjt20111219 你不会找第一次出现的字符8!看输入输出样例都可以发现端倪!


by answerking @ 2023-08-04 16:54:39

@wzb13958817049 什么意思? @Weizhuo_Zhao 它不是只包含小写字母吗? (另外弱弱的说一句,我的代码输入输出样例过了呀)


by Weizhuo_Zhao @ 2023-08-04 17:52:05

@wjt20111219 我想删掉啊~我当时没看~啊啊


by wzb13958817049 @ 2023-08-04 21:07:09

@wjt20111219 就比如说"ba"你的代码输出的是a,你是按字典序排序了,而正确答案是b,第一个只出现一次的字符。


by answerking @ 2023-08-04 21:51:24

已AC,谢高人指点!


|