Posted by 111qqz on Monday, December 14, 2015

## TOC

http://codeforces.com/problemset/problem/1/B 题意：给出了两种表格的表示方法。要求互相转化。 思路：直接模拟即可。注意和一般的进制转化不同的是，26进制对应的是1到26而不是0到25，所以要记得处理下借位。

``````/* ***********************************************
Author :111qqz
Created Time :2015年12月13日 星期日 19时46分09秒
File Name :code/cf/problem/1B.cpp
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#define fst first
#define sec second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ms(a,x) memset(a,x,sizeof(a))
typedef long long LL;
#define pi pair < int ,int >
#define MP make_pair

using namespace std;
const double eps = 1E-8;
const int dx4[4]={1,0,0,-1};
const int dy4[4]={0,-1,1,0};
const int inf = 0x3f3f3f3f;

char st[100];
int a26[100];
int a10[100];

void pre()
{
a26[0]=1;
for ( int i = 1 ;i<=5; i++)
{
a26[i] = a26[i-1]*26;
//	cout<<"i:"<<i<<" "<<a26[i]<<endl;
}
a10[0] = 1;
for ( int i = 1 ; i<=7 ; i++)
{
a10[i] = a10[i-1]*10;
}
}
void solve()
{
cin>>st;
int len = strlen(st);
int p1=-1,p2=-1;
for ( int i = 0 ; i < len ; i++)
{
char ch = st[i];
if (ch>='A'&&ch<='Z')
{
if (p1==-1)
{
p1 = i ;
}
else
{
p2 = i;
break;
}
}
}
if (p2-p1==1||p2==-1)
{
int dig = 0 ;
int alp = 0;
int sum = 0 ;
int sum2 = 0 ;
for ( int i = len -1 ; i>= 0 ; i--)
{
char ch = st[i];
if (!isdigit(ch))
{
sum += (ch-'A'+1)*a26[alp];
alp++;
}
else
{
sum2+= (ch-'0')*a10[dig];
dig++;
}
}
printf("R%d\n",sum2,sum);
}
else
{
int dig1 = 0 ;
int dig2 = 0;
int sum1 = 0 ;
int sum2 = 0 ;
int p = 1;
for ( int i = len-1 ; i>= 0 ; i-- )
{
char ch = st[i];
if (isdigit(ch))
{
//	cout<<"ch:"<<ch<<endl;
if (p)
{
sum1+=(ch-'0')*a10[dig1];
//  cout<<"sum1:"<<sum1<<endl;
dig1++;
}
else
{
sum2+=(ch-'0')*a10[dig2];
dig2++;
}

}
else
{
p = 0 ;
}
}
//	cout<<"sum1:"<<sum1<<" sum2:"<<sum2<<endl;
int cnt = 0 ;
int b[50];
while(sum1)
{
cnt++;
b[cnt] = sum1;
sum1/=26;
//		cout<<"sum1::::"<<sum1<<endl;
}
//	    cout<<"cnt:"<<cnt<<endl;
for ( int i = 1 ; i <= cnt -1 ; i ++)
{
if (b[i]<=0)
{
b[i]+=26;
b[i+1]--;
}
}
while (b[cnt]==0) cnt--;

for ( int i = cnt ; i >=1 ; i--)
{

//	cout<<"b[i]:"<<b[i]<<endl;
cout<<char(b[i]+'A'-1);
}
cout<<sum2<<endl;

}

}
int main()
{
#ifndef  ONLINE_JUDGE
freopen("code/in.txt","r",stdin);
#endif

pre();
int T;
cin>>T;
while (T--)
{
solve();
}

#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0;
}
``````

「真诚赞赏，手留余香」