代码:
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
bool Check(string &str) // false system 1, true system 2
{
if(str[0] != 'R')
return false;
if(!isdigit(str[1]))
return false;
for(int i = 2; i < str.size(); ++i)
{
if(str[i] == 'C')
return true;
}
return false;
}
void ConvertTo1(string &str)
{
int pos = 2;
while(str[pos] != 'C')
{
++pos;
}
string col(str.begin() + 1, str.begin() + pos);
string b(str.begin() + pos + 1, str.end());
int row = atoi(b.c_str());
vector<int> ans;
while(row)
{
row = row - 1;
ans.push_back(row % 26);
row /= 26;
}
for(int i = ans.size() - 1; i >= 0; --i)
{
printf("%c", 'A' + ans[i]);
}
printf("%s", col.c_str());
}
void ConvertTo2(string &str)
{
int row = 0, pos = 0;
while(!isdigit(str[pos]))
{
row = row * 26 + str[pos] - 'A' + 1;
++pos;
}
string col(str.begin() + pos, str.end());
printf("R%sC%d", col.c_str(), row);
}
int main()
{
//freopen("F://input.txt", "r", stdin);
int n;
scanf("%d", &n);
while(n--)
{
string str;
cin >> str;
if(Check(str))
ConvertTo1(str);
else
ConvertTo2(str);
printf("\n");
}
return 0;
}