単純なパスワード(C ++ Huaweiマシンテスト)

問題解決のアイデア:

(1)順番に判断する

#include<iostream>

using namespace std;

string helper(string &str) {
    string s="";
    for(int i=0;i<str.length();i++) {
        if('A'<=str[i] && str[i]<='Z') {
            char temp = (char)(str[i]+33);
            if(temp>'z') s+='a';
            else s+=temp;
        } else if('a'<=str[i] && str[i]<='c') s+='2';
        else if('d'<=str[i] && str[i]<='f') s+='3';
        else if('g'<=str[i] && str[i]<='i') s+='4';
        else if('j'<=str[i] && str[i]<='l') s+='5';
        else if('m'<=str[i] && str[i]<='o') s+='6';
        else if('p'<=str[i] && str[i]<='s') s+='7';
        else if('t'<=str[i] && str[i]<='v') s+='8';
        else if('w'<=str[i] && str[i]<='z') s+='9';
        else s+=str[i];
    }
    return s;
}
int main() {
    string str;
    while(cin>>str) {
        cout<<helper(str)<<endl;
    }
    return 0;
}

 

おすすめ

転載: blog.csdn.net/coolsunxu/article/details/114734582