返回题解分享
讨论 / 题解分享/ 帖子详情

字符串编号(编程题) - 题解

#include <bits/stdc++.h>
using namespace std;

int main()
{
    map<int, string> dictionary{{26,"Z"},{25,"Y"},{24,"X"},{23,"W"},{22,"V"},{21,"U"},{20,"T"},{19,"S"},{18,"R"},{17,"Q"},{16,"P"},{15,"O"},{14,"N"},{13,"M"},{12,"L"},{11,"K"},{10,"J"},{9,"I"},{8,"H"},{7,"G"},{6,"F"},{5,"E"},{4,"D"},{3,"C"},{2,"B"},{1,"A"}};  //真是打打又表表啊
    string str;
    getline(cin, str);
    int temp;
    for(int i=0; i<str.size(); i++)
    {
        if(str.substr(i, 2)>"26")
        {
            temp=stoi(str.substr(i,1));
            cout << dictionary[temp];
        }
        else
        {
            temp=stoi(str.substr(i,2));
            cout << dictionary[temp];
            if(temp>9)
            {
                i++;
            }
        }
    }
    return 0;
}
0 回复 0 转发 0 喜欢 5 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!