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;
    }
    
    生命不息,奋斗不止,这才叫青春,青春就是拥有热情相信未来。
  • 相关阅读:
    IntelliJ IDEA导包快捷键
    maven命令创建web骨架项目
    v2.0版本小程序开发心得(代码之外)
    装饰器模式
    闭包
    git diff的文字说明
    WSGI和CGI
    word-wrap、white-space和word break的区别
    Javascript中正则的 match、test、exec使用方法和区别
    Git 内部原理
  • 原文地址:https://www.cnblogs.com/lyf-acm/p/5784548.html
Copyright © 2011-2022 走看看