B.Spreadsheets

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

2
R23C55
BC23

Output

BC23
R23C55

题意:转化excel表格(26进制转化)
就举样例给的栗子吧:
R23C55 表示23行55列 把23行55列坐标写出来
BC23 表示一个坐标是BC23 写出他的多少行多少列

题解:注意3点就很简单了
1.输入怎么判断是哪种形式 判断第一种就行了 输入一个string
判断 s[0]= =‘R’ && s[1]<=‘9’ && s[1]>=‘0’ && k2>=2 && k1= =0
2.十进制转26进制
因为A 和 Z对26取余都是0 所以让(sum-1)%26+‘A’ 然后sum/=(sum-1)/26 循环就行了
3.26进制转10进制 :
w=w26+u[i]-‘A’+1;(w初始值为0)
这样好像不理解,大家可以模拟下10进制,
345
1. ans=0 ans=ans
10+3=3;
2. ans=3 ans=ans10+4=34;
3. ans=34 ans=ans
10+5=345;

解决这些问题就很简单了
AC代码:

#include<iostream>
#include<cmath>
typedef long long ll; 
using namespace std;
char p[26];
int main()
{
	ll t;
	cin>>t;
	while(t--)
	{
		string s;
		cin>>s;
		ll k1=-1,k2=-1;
		for(ll i=0;i<s.length();i++)
		{
			if(s[i]=='R')
				k1=i;
			else if(s[i]=='C')
				k2=i;
		}
		if(s[0]=='R'&&s[1]<='9'&&s[1]>='0'&&k2>=2&&k1==0)
		{
			ll r=0,c=0;
			for(ll i=1;i<k2;i++)
			{
				r=r*10+(s[i]-'0');
			}
			for(ll i=k2+1;i<s.length();i++)
			{
				c=c*10+(s[i]-'0');
			}
		//	cout<<r<<" "<<c<<endl;
			ll k=0;
			while(c)
			{
				p[k++]=(c-1)%26+'A';
				c=(c-1)/26;
			}
			for(ll i=k-1;i>=0;i--)
				cout<<p[i];
			cout<<r<<endl;
		}	
		else
		{
			char u[26];
			ll k3;
			for(ll i=0;i<s.length();i++)
			{
				if(s[i]<='Z'&&s[i]>='A')
					continue;
				else
				{
					k3=i;
					break;
				}
			}	
			ll o=0;
			for(ll i=0;i<k3;i++)
			{
				u[i]=s[i];	
			} 
			ll w=0;
//			for(int i=0;i<k3;i++)
//			{
//				cout<<u[i]<<" ";
//			}
//			cout<<endl;
			for(ll i=0;i<k3;i++)
			{
				w=w*26+u[i]-'A'+1;
				
			}
			for(ll i=k3;i<s.length();i++)
			{
				o=o*10+(s[i]-'0');
			}
		//	cout<<o<<endl;
			cout<<"R"<<o<<"C"<<w<<endl;
			
		}
		
	} 
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

aaHua_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值