蓝桥杯 年号子串

小明用字母 A 对应数字 1,B 对应 2,以此类推,用 Z 对应 26。对于 27 以上的数字,小明用两位或更长位的字符串来对应,例如 AA 对应 27AB对应 28,AZ 对应 52LQ 对应 329。

请问 2019 对应的字符串是什么?

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char a[26]= {'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};;
int main()
{
    int n;
    cin >> n;
    string ans = "";
    while(n){
        n--;// 因为26进制是 0 - 25,而题目中表示是 1 - 26,所以每一位都减1
        int now = n % 26;
        ans += a[now];
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

 

posted @ 2022-04-08 20:10  弈星  阅读(44)  评论(0)    收藏  举报