行列转换

题目描述:

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.

数据范围n是10的5次方行列都不会超过10的6次方;

一次codeforce的题,今天被坑的很惨,看到题的第一反应是用26进制去转换编码,但是0和z的那个地方总是处理不好,于是换了思路发现可以直接转换,另外判断两种字符串类型的时候也需要注意一下。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
const int MAXM=1000006;


int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        string s;
        cin>>s;
        int len=s.size();
        bool flag=true;
        if (s[0]=='R'&&s[1]<='9'&&s[1]>='1')
        {
            for (int i=2;i<len;i++)
                if (s[i]=='C')
            {
                flag=false;
                break;
            }
        }
        if (!flag)
        {
            int row=0;
            int i;
            for (i=1;s[i]!='C';i++)
                row=row*10+s[i]-'0';
            int j;
            int col=0;
            for (j=i+1;j<len;j++)
                col=col*10+s[j]-'0';
            stack<char > s1;
            while(col)
            {
                char c='A'+(col-1)%26;
                s1.push(c);
                col=(col-1)/26;
            }
            while(!s1.empty())
            {
                printf("%c",s1.top());
                s1.pop();
            }
            printf("%d\n",row);
        }
        else
        {
            int i=0,y=0;
            while(1)
            {
                y=y*26+s[i]-'A'+1;
                i++;
                if (s[i]<='9'&&s[i]>='1')
                    break;
            }
            int x=0;
            for (int j=i;j<len;j++)
            {
                x=x*10+s[j]-'0';
            }
            printf("R%dC%d\n",x,y);

        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值