zzuli 1706 (来源:GDUT 2015年校赛 初赛)
题目描述
假如没有阿拉伯数字,我们要怎么表示数字呢
小明想了一个方法如下:
1 -> A
2 -> B
3 -> C
....
25 -> Y
26 -> Z
27 -> AA
28 -> AB
....
现在请你写一个程序完成这个转换
输入
输入的第一个数为一个正整数T,表明接下来有T组数据。
每组数据为一个正整数n ( n <= 1000)
输出
对于每个正整数n,输出他对应的字符串
样例输入
3
1
10
27
样例输出
A
J
AA
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;
char ans[1000];
int main() {
int T, n;
scanf("%d", &T);
while(T--) {
int num = 0;
scanf("%d", &n);
while(n) {
int t = (n - 1) % 26;
ans[num++] = (char)(t + 'A');
n = (n - 1) / 26;
}
for(int i = num - 1; i >= 0; i--) {
printf("%c", ans[i]);
}
printf("\n");
}
return 0;
}