B. Spreadsheets Codeforces Beta Round 1

该编程问题要求将给定的Excel单元格坐标,如A1到AZ100000和R1C1到R100000C100000,按照另一种编号系统(例如RXCY)进行转换。

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.

Examples

input

Copy

2
R23C55
BC23

output

Copy

BC23
R23C55

题目大致意思:给两种日期记录模式,让我们相互转换。

日期记录模式一:日期一、字母(26进制,不超过26不进位),日期二、数字。

日期记录模式二:日期二、"R"+数字,日期一、"C"+数字。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"

void solve(){
	string s;
	cin >> s;
	ll x,y,a=0,b=0;
	bool f=true,pd=false;
	map<char,ll>mp;
	for(ll i = 0 ; i < s.size() ;  i++)
		if(s[i] >= 'A' && s[i] <= 'Z')mp[s[i]]++;
	if(mp['C'] != 1 || mp['R'] != 1 || mp.size() != 2)f=false;
	if(f)
		for(ll i = 1 ; i < s.size() ; i++)
			if(s[i]>='A' && s[i] <='Z')
				if(s[i-1] >= '0' && s[i-1] <= '9')pd=true;
	if(f && pd){
		x=s.find("R");
		y=s.rfind("C");
		for(ll i = 1 ; i < s.size() ; i ++){
			if(i < y)a=a*10+s[i]-'0';
			else if(i > y)b=b*10+s[i]-'0';
		}
		s="";
		while(b){
			if(b%26 == 0){
				s='Z'+s;
				b--;
			}else s=char('A'+b%26-1)+s;
			b/=26;
		}
		cout << s << a << endl;
	}else{
		for(ll i = 0 ; i < s.size() ; i ++){
			if(s[i] >= 'A' && s[i] <= 'Z')a=a*26+s[i]-'A'+1;
			else b=b*10+s[i]-'0';
		}
		cout << "R" << b << "C" << a << endl;
	}
	return;
}

int main(){
	ll t=1;cin >> t;
	while(t--)solve();
	return 0;
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值