神奇的编码 【进制转换】

神奇的编码
Description
假如没有阿拉伯数字,我们要怎么表示数字呢
小明想了一个方法如下:
1 -> A
2 -> B
3 -> C
….
25 -> Y
26 -> Z
27 -> AA

28 -> AB
….

现在请你写一个程序完成这个转换

Input
输入的第一个数为一个正整数T,表明接下来有T组数据。
每组数据为一个正整数n ( n <= 1000)

Output
对于每个正整数n,输出他对应的字符串

Sample Input
3
1
10
27
Sample Output
A
J
AA

进制转换?

#include <stdio.h>    
#include <iostream>    
#include <math.h>    
#include <stdlib.h>    
#include <ctype.h>    
#include <algorithm>    
#include <vector>    
#include <string.h>    
#include <queue>    
#include <stack>    
#include <set>     
#include <sstream>    
#include <time.h>    
#include <utility>    
#include <malloc.h>    
#include <stdexcept>    
#include <iomanip>    
#include <iterator>  

using namespace std;

int main()
{
    int n,t;
    scanf("%d",&t);
    while (t--)
    {
        scanf("%d",&n);
        if (n <= 26)
            printf("%c\n", 'A' + n - 1);
        else if (n <= 26 * 26 + 26)
        {
            n -= 27;
            int t = n / 26;
            printf("%c", 'A' + t);
            n = n % 26;
            printf("%c\n", 'A' + n);
        }
        else
        {
            n -= 27 + 26 * 26;
            printf("%c%c%c\n", 'A' + char(n / 26 / 26), 'A' + char((n / 26) % 26), 'A' + char(n % 26));
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值