精彩编码 【进制转换】

精彩编码
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;
}

版权声明:转载请注明出处。

posted @ 2015-08-24 19:53  yxwkaifa  阅读(254)  评论(0编辑  收藏  举报