历届试题 Excel地址
Excel单元格的地址表示很有趣,它使用字母来表示列号。 比如, A表示第1列, B表示第2列, Z表示第26列, AA表示第27列, AB表示第28列, BA表示第53列, …
当然Excel的最大列号是有限度的,所以转换起来不难。 如果我们想把这种表示法一般化,可以把很大的数字转换为很长的字母序列呢?
Input
本题目即是要求对输入的数字,
Output
输出其对应的Excel地址表示方式。
Examples
样例输入 26 样例输出 Z 样例输入 2054 样例输出 BZZ
Hint
题意:
题解:
第十届蓝桥杯就考到了几乎一道原题, 所以说打蓝桥杯还是要多刷一刷真题. 这道题不是纯粹的10进制转26进制, 要考虑一点就好了, 题目中所述的进制中没有0, 一切都是从1开始的, 在/26的时候-1就好了
经验小结:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
using namespace std
;
#define ms(x, n) memset(x,n,sizeof(x));
typedef long long LL
;
const int inf
= 1<<30;
const LL maxn
= 1e5+10;
string
tran(int n
){
string res
;
while(n
> 0){
int t
= n
%26;
n
= (n
-1)/26;
if(t
==0) t
=26;
res
+= 'A'+t
-1;
}
for(int i
= 0, j
= res
.length()-1; i
< j
; ++i
, --j
)
swap(res
[i
], res
[j
]);
return res
;
}
int main()
{
int n
;
cin
>> n
;
cout
<< tran(n
) << endl
;
return 0;
}