脑残题。。。。(两种模式字符串互相转换)
还送了几发WA,原因是判断当前字符串是第一种模式还是第二种模式时出错了
代码如下:
/* ***********************************************
Author :yinhua
Created Time :2014年12月12日 星期五 14时06分37秒
File Name :1B.cpp
************************************************ */
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAXN 10010
#define LL long long
using namespace std;
int tmp[MAXN];
char str[10000];
int main() {
char ch1, ch2;
int T, i, row, col;
scanf("%d", &T);
while(T--) {
memset(str, 0, sizeof(str));
scanf("%s", str);
int len = strlen(str);
bool ok = false;
for(i=0; i<len; ++i) {
if(str[i]>='0'&&str[i]<='9') {
ok = true;
continue;
}
if(ok && str[i]>='A'&&str[i]<='Z')
break;
}
//printf("i = %d\n", i);
if(str[0] == 'R' && i!=len) {
sscanf(str, "%c%d%c%d", &ch1, &row, &ch2, &col);
//printf("ch1 = %c\tch2 = %c\n", ch1, ch2);
//printf("%d %d\n", row, col);
int cnt = 0;
while(col) {
if(col%26 == 0) {
tmp[cnt++] = 26;
col = col/26-1;
} else {
tmp[cnt++] = col%26;
col = col/26;
}
}
for(int i=cnt-1; i>=0; --i) {
printf("%c", 'A'+tmp[i]-1);
}
printf("%d\n", row);
} else {
row = col = 0;
for(int i=0; i<len; ++i) {
if(str[i]>='A' && str[i]<='Z') {
col = col*26+(str[i]-'A'+1);
}
if(str[i]>='0' && str[i]<='9') {
row = row*10+(str[i]-'0');
}
}
printf("R%dC%d\n", row, col);
}
}
return 0;
}