1159: Fat Brother’s new way
Time Limit: 1000 MS Memory Limit: 257792 KB
64-bit interger IO format: %lld Java class name: Main
Submit Status Discuss
Description
I bet, except Fat Brothers, all of you don’t like strange way to show integers , he is really like this way to showing integers:
1 -> ‘A’
2 -> ‘B’
…….
26 -> ‘Z’
27 -> ‘AA’
28 -> ‘AB’
…….
Unfortunately, Fat Brother’s mathematics is poor, so he needs your help, he will give you some integers, and you must transform it with Fat Brother’s way.
Input
Input starts with an integer T(T <= 10000), denoting the number of test case.
For each test case, an integers n(1 <= n <= 2147483647) is given.
Output
For each case, output the corresponding string with upper-case letters.
Sample Input
3
17311
2068
37
Sample Output
YOU
CAN
AK
其实就是一个类似进制转换的问题,这里是26进制。但是有个不一样的地方就是如果模出来是0其实代表的是z。再有一个就是比如52,答案是AZ。根据正常的进制转换除26结果为2,2本来对应的是B但是这边实际上是A,就是在这种整26倍的情况下要做一些特殊的判断。
#include "cstring"
#include "cstdio"
#include "iostream"
#include "string.h"
#include "stack"
using namespace std;
int main()
{
int cas;
scanf("%d",&cas);
while(cas--)
{
int n;
scanf("%d",&n);
stack<int> list;
while(n)
{
if(n<=26)
{
list.push(n);
break;
}
int temp=n%26;
if(temp==0)
temp=26;
list.push(temp);
int oldn=n;
n=n/26;
if(n*26==oldn)
n--;
}
while(!list.empty())
{
int temp=list.top();
list.pop();
printf("%c",'A'+temp-1);
}
printf("\n");
}
}