题目链接
26进制的问题, 坑点在于这道题进制中没有 0 有26(z)注意到这点就可以水过了
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#define ll long long
using namespace std;
char str[3000005];
char zimu[1000000];
void chuli()
{
if(str[0]!='R')
{
ll sum=0;
int i;
for(i=0;str[i]<='Z'&&str[i]>='A';++i)
{
sum*=26;
sum+=str[i]-'A'+1;
}
ll num=atoi(str+i);
cout<<"R"<<num<<"C"<<sum<<endl;
return ;
}
int len=strlen(str);
if(str[1]<='Z'&&str[1]>='A')
{
ll sum=0;
int i;
for(i=0;str[i]<='Z'&&str[i]>='A';++i)
{
sum*=26;
sum+=str[i]-'A'+1;
}
ll num=atoi(str+i);
cout<<"R"<<num<<"C"<<sum<<endl;
return ;
}
int cwei=0;
for(int i=1;i<len;++i)
{
if(str[i]=='C')
{
cwei=i;
break;
}
}
if(cwei==0)
{
ll num=atoi(str+1);
cout<<"R"<<num<<"C18"<<endl;
return ;
}
ll num1=atoi(str+1);
ll num2=atoi(str+cwei+1);
int chu=0;
while(num2)
{
int nc=num2%26;
if(nc==0){zimu[chu]='Z';num2--;}
else
zimu[chu]='A'+nc-1;
chu++;
num2/=26;
}
for(int i=chu-1;i>=0;--i)
cout<<zimu[i];
cout<<num1<<endl;
}
int main()
{
int T;
cin>>T;
getchar();
while(T--)
{
gets(str);
chuli();
}
return 0;
}