87hbteo

描述

我们都知道Excel的列数是用字母表示的,比如第1列对应A,第27列对应AA。

假设给定一个正整数n,你能给出它所对应的字母表示么?

输入格式

程序需要读入多个测试样例,每个测试样例中:

一个正整数n(0 < n < 200000)

输出格式

对每个测试样例:

所对应的字母表示

样例输入

26
171135

样例输出

Z
ISDC

资源约定

峰值内存消耗 < 256M

CPU消耗 < 2000ms


请严格按要求输出,不要画蛇添足地打印类似:“请您输入...” 的多余内容。

 

所有代码放在同一个源文件中,调试通过后,拷贝提交该源码。

[C]

注意: main函数需要返回0

注意: 只使用ANSI C/ANSI C++ 标准,不要调用依赖于编译环境或操作系统的特殊函数。

注意: 所有依赖的函数必须明确地在源文件中 #include <xxx>, 不能通过工程设置而省略常用头文件。

[Java]

注意:不要使用package语句。不要使用jdk1.7及以上版本的特性。

注意:主类的名字必须是:Main,否则按无效代码处理。

Author

imcmy


AC代码:
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <math.h>
using namespace std;
typedef long long ll;
const int maxn = 1000 + 5;
const int mods = 1e9 + 7;

int num[20000];

int main(){
    int n;
    while(scanf("%d",&n)==1){
        if(n<=26){
             printf("%c\n",\'A\'+n-1);
             continue;
        }
        int len=0;
        while(n!=0){
            num[len]=(n%26-1);
            if(num[len]==-1)num[len]=25;
            if(n%26==0)n=n/26-1;
            else n=n/26;
            len++;
        }
        for(int i=len-1;i>=0;i--){
            printf("%c",\'A\'+num[i]);
        }
        printf("\n");
    }
    return 0;
}

 

分类:

技术点:

相关文章:

  • 2021-07-20
  • 2021-09-22
  • 2021-07-31
  • 2022-01-07
  • 2021-12-25
  • 2021-08-06
  • 2022-01-07
猜你喜欢
  • 2022-01-07
  • 2022-01-07
  • 2022-01-07
  • 2022-01-07
  • 2022-01-07
  • 2021-07-20
  • 2021-04-13
相关资源
相似解决方案