当前位置:网站首页>Wonderful coding [hexadecimal conversion]

Wonderful coding [hexadecimal conversion]

2022-07-06 19:49:00 Full stack programmer webmaster

Hello everyone , I meet you again , I'm the king of the whole stack .

Wonderful coding Description If there are no Arabic numerals , We want to figure out how to represent numbers Xiao Ming thinks a way , Like the one below : 1 -> A 2 -> B 3 -> C …. 25 -> Y 26 -> Z 27 -> AA

28 -> AB ….

Now please write a program to complete this conversion

Input The first number entered is a positive integer T, Indicates that there is T Group data . Each group of data is a positive integer n ( n <= 1000)

Output For every positive integer n, Output his corresponding string

Sample Input 3 1 10 27 Sample Output A J AA

Hexadecimal conversion ?

#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;
}

Copyright notice : Reprint please indicate the source .

Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/117143.html Link to the original text :https://javaforall.cn

原网站

版权声明
本文为[Full stack programmer webmaster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207061146428848.html