美文网首页
poj1298 模拟(字母替换)

poj1298 模拟(字母替换)

作者: 暖昼氤氲 | 来源:发表于2019-11-08 14:45 被阅读0次
    /*
    Time:2019.11.8
    Author: Goven
    type:模拟(字母替换) 
    err:
    ref: 
    */
    #include<iostream>
    #include<string>
    #include<map> 
    using namespace std;
    
    int main()
    {
        map<char, char> mp;
        for (char c = 'A'; c <= 'Z'; c++) {
            mp[c] = 'A' + (c - 'A' - 5 + 26) % 26;
        }
        string str;
        while (getline(cin, str) && str != "ENDOFINPUT") {
            while (getline(cin, str) && str != "END") {
                int l = str.length();
                for (int i = 0; i < l; i++) {
                    if (str[i] >= 'A' && str[i] <= 'Z') {
                        cout << mp[str[i]];
                    }
                    else cout << str[i];
                }
                cout << endl;
            }
            
        }
        return 0;
    }
    
    //更简单的写法:https://blog.csdn.net/qq_36258516/article/details/70877479
    #include<iostream>
    #include<string>
    #include<map> 
    using namespace std; 
    int main(){
        string a = "VWXYZABCDEFGHIJKLMNOPQRSTU";
        string str;
        while (getline(cin, str)) {
            if (str == "ENDOFINPUT") break;
            if (str == "START" || str == "END") continue;
            for (int i = 0; i < str.length(); i++) {
                if (str[i] >= 'A' && str[i] <= 'Z') {
                    str[i] = a[str[i] - 'A'];
                }
            }
            cout << str << endl;
        }
    } 
    

    相关文章

      网友评论

          本文标题:poj1298 模拟(字母替换)

          本文链接:https://www.haomeiwen.com/subject/kvaibctx.html