B. Spreadsheets
B. Spreadsheets
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
#define ll long long
char a[maxn];
int temp[maxn];
char zimu[maxn],shuzi[maxn];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ll r,c;
scanf("%s",a);
if(sscanf(a,"R%lldC%lld",&r,&c)==2)
{
int cnt=0;
while(c!=0)
{
temp[++cnt]=(c-1)%26;
c=(c-1)/26;
}
for(int i=cnt; i>=1; i--)
printf("%c",'A'+temp[i]);
printf("%lld\n",r);
}
else
{
int len=strlen(a);
int cnt1,cnt2;
cnt1=cnt2=0;
for(int i=0; i<len; i++)
{
if(a[i]<='Z'&&a[i]>='A')
zimu[++cnt1]=a[i];
else
shuzi[++cnt2]=a[i];
}
shuzi[++cnt2]='\0';
printf("R%sC",shuzi+1);
ll num=0;
for(int i=1; i<=cnt1; i++)
{
num=num+zimu[i]-'A'+1;
// printf("zimu%d\n",zimu[i]-'A'+1);
num=num*26;
}
num/=26;
printf("%lld\n",num);
}
}
}