FJNUOJ1159

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");

    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值