码迷,mamicode.com
首页 > 其他好文 > 详细

神奇的编码

时间:2015-03-16 21:15:13      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:

神奇的编码
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;
}

神奇的编码

标签:

原文地址:http://blog.csdn.net/u014427196/article/details/44313217

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!