zoukankan      html  css  js  c++  java
  • 1B -- Spread sheet

    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.

    Examples
    Input
    2
    R23C55
    BC23
    Output
    BC23
    R23C55

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<string>
    using namespace std;
    
    char a[18];
    int main()
    {
        int n,i;
        cin>>n;
        while(n--)
        {
    		cin>>a;
    		int len = strlen(a);
    		int flag = 0;
    		int cnt = 0;
    		for(i=1;i<len;i++)
    		{
    			if((a[i]>='0'&&a[i]<='9')&&(a[i-1]>='A'&&a[i-1]<='Z'))
    			cnt++;
    		}
    		if(cnt==1)     //判断是哪种情况
    			flag=1;
    		if(flag)     //输入BC23类似的
    		{ 
    			int t1=0,t2=0;
    			for(i=0;i<len;i++)
    			{
    				if(a[i]>='A'&&a[i]<='Z')
    					t1=t1*26+(a[i]-'A'+1);
    				else
    					t2=t2*10+(a[i]-'0');
    			}
    			cout<<"R"<<t2<<"C"<<t1<<endl;
    		}
    		else
    		{          //输入R23C55类似的
    			int t1=0, t2=0;
    			for(i=1;i<len;i++)
    			{
    				if(a[i]>='0'&&a[i]<='9')
    					t1=t1*10+(a[i]-'0');
    				else
    					break;
    			}
    			for(int j=i+1;j<len;j++)
    			{
    				if(a[j]>='0'&&a[j]<='9')
    				t2=t2*10+(a[j]-'0');
    			}
    
    			char rs[12],res[12];
    			int xx=-1;
    			while(t2)
    			{
    				int num=t2%26;
    				if(num==0)
    				{
    					rs[++xx]='Z';   //这里需要分类,为Z的时候特殊
    					t2--;
    				}
    				else
    					rs[++xx]=num-1+'A';
    				t2/=26;
    			}
    			for(i=0;i<=xx;i++)
    				res[i]=rs[xx-i];
    			res[++xx]='';
    			cout<<res<<t1<<endl;
    		}
        }
        return 0;
    }
    
    生命不息,奋斗不止,这才叫青春,青春就是拥有热情相信未来。
  • 相关阅读:
    自己用的vim插件
    关于利用python进行验证码识别的一些想法
    看看黑客如何破解验证码机制
    不懂技术的人不要对懂技术的人说这很容易实现
    4个mysql客户端工具的比较
    GB2312,GBK和UTF-8的区别
    Windows下用Python你会几种copy文件的方法?
    python3.4连接mysql数据库的方法
    python3操作mysql教程
    python win32com
  • 原文地址:https://www.cnblogs.com/lyf-acm/p/5784548.html
Copyright © 2011-2022 走看看