您的位置:首页 > 其它

1B. Spreadsheets

2015-09-24 23:58 197 查看
题目大意:

行和列的两种方式。
A是1, B是2,....Z是26, AA是27, AB是28...........
如: BC23代表55列23行
还有一种表示方法:R23C55, 代表23行,55列。

要求这两种数字之间相互转化。
=========================================================================
需要注意的就是两点:
1. 每个数字对26取余数后要再 - 1,再+‘A’ 就是答案了。
2. 如果余数是0则要对C--,并且输出的字符是Z、

#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
using namespace std;
typedef long long LL;
const LL INF = 0xffffff;
const int maxn = 201315;
const LL MOD = 1e9+7;
void Putt(int C)
{
if(C == 0)
return ;
if(C%26 == 0)
Putt((C-1)/26);
else
Putt(C/26);
char ch;
if(C%26 == 0)
ch = 'Z';
else
ch = C%26 + 'A' - 1;
printf("%c", ch);
}

void ChangeOne(char str[])
{
int R, C;
sscanf(str,"R%dC%d", &R, &C);

Putt(C);
printf("%d\n", R);
}

void ChangeTow(char str[])
{
int num = 0, i;
for(i=0; str[i] >= 'A' && str[i] <= 'Z'; i++)
{
num = num*26 + str[i] - 'A' + 1;
}
printf("R%sC%d\n",str+i, num);
}
bool Ok(char str[])
{
if(str[0] == 'R' && str[1] >= '0' && str[1] <= '9')
{
for(int i=1; str[i]; i++)
{
if(str[i] == 'C')
return true;
}
}
return false;
}

int main()
{
int T;
char str[105];
scanf("%d", &T);
while(T--)
{
cin >> str;

if(Ok(str))
ChangeOne(str);
else
ChangeTow(str);

}
return 0;
}
/*
26 Z
27 AA
53 BA
BZ 78
CA 79
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: