Analog base, but note that the letters are not exactly 26 bases. It can be found that the nth and n-1th bits may be equivalent to A0=Z, so when converting from the ones digit to a decimal number, it is judged as Z , Write 0 when encountering Z, and advance one to the high bit.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,m,a,ans,ans2;
int i,j,k;
char iptch[999];
char ansch[99];
int anschlen;
void num2a (int o)
{int i;
anschlen = 0;
while (o)
{// printf (",,% d ,,", o);
if (o% 26 == 0)
{ansch [++ anschlen] = 'Z';
o- = 26;
} else
{ ansch [++ anschlen] = 'A' + (o% 26) -1; // printf ("qq% dpp% dpp", o, (o% 26)); } o / = 26; } }
int main()
{
scanf("%lld",&n);
while(n--)
{
scanf("%s",iptch+1);
m=strlen(iptch+1);
bool isrc=false;
int bj=0;
int bj2=0;
for (i=2;i<=m;i++)//判断类型
{
if( iptch[i]>='A'&&iptch[i]<='Z'&&iptch[i-1]>='0'&&iptch[i-1]<='9'){isrc=true;bj=i-1;}
if( iptch[i-1]>='A'&&iptch[i-1]<='Z'&&iptch[i]>='0'&&iptch[i]<='9'){bj2=i-1;}
}
if(isrc)
{//get shi
ans=0;
for(i=2;i<=bj;i++)
ans=ans*10+iptch[i]-'0';
ans2=0;
for(i=bj+2;i<=m;i++)
ans2=ans2*10+iptch[i]-'0';
// printf(",,%lld,, ",ans2);
num2a(ans2);
for(i=anschlen;i>=1;i--)
{
printf("%c",ansch[i]);
}
printf("%lld",ans);
}else
{
ans=0;
for(i=1;i<=bj2;i++)
ans=ans*26+(iptch[i]-'A'+1);
ans2=0;
for(i=bj2+1;i<=m;i++)
ans2=ans2*10+iptch[i]-'0';
printf("R%lldC%lld",ans2,ans);
}
printf("\n");
}
}