coj 1140 序号互换

本文探讨了进制转换的技巧及如何处理边界条件,通过示例代码展示了解决复杂进制转换问题的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

进制转换,注意边界(WA 5次)。

测试数据:26 27 52 160 Z FD

结果:  Z AA AZ FD 26 160

# include <stdio.h>
# include <ctype.h>
# include <memory.h>
 
char a[15];
char s[15];
 
int main()
{
    int T, i, n;

    scanf("%d", &T);
    while (T--)
    {
        scanf("%s", a);
        if (isdigit(a[0]))
        {
            i = 0;
            n = atoi(a);
            while  (n > 0)
            {
                s[i] = (n+25) % 26 + 'A'; 
                ++i;
                if (n % 26) n /= 26;
                else {n /= 26; --n;}
            }
            while (i > 0) putchar(s[--i]);
            putchar('\n');
            memset(s, 0, sizeof(s));
        }
        else
        {
            i = n = 0;
            while (a[i] != '\0')
            {
                n = 26*n + a[i]-'A'+1;
                ++i;
            }
            printf("%d\n", n);
        }
         
    }
     
    return 0;
}

 

转载于:https://www.cnblogs.com/JMDWQ/archive/2012/04/14/2447411.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值