zoukankan      html  css  js  c++  java
  • 精彩编码 【进制转换】

    精彩编码
    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
    ", 'A' + n - 1);
            else if (n <= 26 * 26 + 26)
            {
                n -= 27;
                int t = n / 26;
                printf("%c", 'A' + t);
                n = n % 26;
                printf("%c
    ", 'A' + n);
            }
            else
            {
                n -= 27 + 26 * 26;
                printf("%c%c%c
    ", 'A' + char(n / 26 / 26), 'A' + char((n / 26) % 26), 'A' + char(n % 26));
            }
        }
        return 0;
    }

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

  • 相关阅读:
    arguments.callee
    vue的生命周期
    Vue中的v-cloak用法
    控制input只能输入数字和两位小数
    css3新单位vw、vh的使用详解
    关于图片的Base64编码
    Logic and Fault simulation
    scan design flow(二)
    scan design flow(一)
    异构计算
  • 原文地址:https://www.cnblogs.com/yxwkf/p/4755734.html
Copyright © 2011-2022 走看看