cf 1B. Spreadsheets

http://codeforces.com/problemset/problem/1/B

B. Spreadsheets
time limit per test
10 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.

The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23.

Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example.

Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system.

Input

The first line of the input contains integer number n (1 ≤ n ≤ 105), the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 .

Output

Write n lines, each line should contain a cell coordinates in the other numeration system.

Sample test(s)
Input
2
R23C55
BC23
Output

BC23R23C55

//太恶心了,这转换到吐血
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
using namespace std;
#define N 10010
char s[N];
void to(int k){
	stack<int>p;
	while(k){	
		p.push(k%26);k/=26;
	};
	int i,l=0;
	while(!p.empty()){
		//cout<<p.top()<<endl;
		 k=p.top()-1;
		 s[l++]='A'+k;
		//printf("%c",'A'+k);
		 p.pop();
	}s[l]='\0';
	//cout<<s<<endl;
	for(k=0,i=l-1;i>0;i--){
		s[i]+=k;
		if(s[i]<'A'){
			s[i]=s[i]+26;k=-1;
		}else k=0;
	}
	i=0;
	if(k==-1){
		if(s[0]=='A')i=1;
		else s[0]--;
	}
	printf("%s",s+i);
}
void fun(int k){//R123C123
	int x=0,y=0,i;
	for(i=1;i<k;i++)x=x*10+s[i]-'0';
	for(i=k+1;s[i];i++)y=y*10+s[i]-'0';
	to(y);printf("%d\n",x);
}
int main(){
	int T,i,j;
	scanf("%d",&T);
	while(T--){
		scanf("%s",s);
		i=1;
		if(s[0]=='R'&&s[1]>='0'&&s[1]<='9'){
			for(i=2;s[i];i++)
				if(s[i]=='C'){fun(i);i=-1;break;}
		}
		//ABC123
		if(i!=-1){
		int x=0,y=0;
		for(i=0;s[i]<='Z'&&s[i]>='A';i++){
			x=x*26+(s[i]-'A'+1);
		}
		for(;s[i];i++)y=y*10+s[i]-'0';
		printf("R%dC%d\n",y,x);
		}
	}
return 0;
}


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值