CodeForces 1B Spreadsheets(implementation math)——Codeforces Beta Round #1

本文介绍了一个简单的程序,用于实现两种不同表格坐标系统之间的转换:一种是使用字母表示列的坐标系统,另一种是使用R(int)C(int)形式的坐标系统。文章提供了完整的代码示例,并解释了如何区分输入的坐标属于哪种系统。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

Sample test(s)
input
2
R23C55
BC23
output
BC23
R23C55

/*********************************************************************/

题意:两个系统间的表示法转化

spreadsheets systems用字符表示列,"A"~"Z"分别表示1~26,"AA"~"AZ"表示27~52,依次类推;数字表示行。例如,BC23表示第23行第55列。

numeration system用R(int)C(int)表示。例如,R23C55表示第23行第55列。

其实这道题就是简单的字符串处理,关键是如何辨别给定的是哪种系统的表示法,只有解决这个问题,其他的就没有什么大问题了

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<stdlib.h>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#define exp 1e-10
using namespace std;
const int N = 40001;
const int inf = 1000000000;
const int mod = 2009;
char s[N],w[4][N];
int main()
{
    int t,i,j,k,r,c;
    bool flag;
    scanf("%d",&t);
    while(t--)
    {
        memset(w,0,sizeof(w));
        scanf("%s",s);
        for(flag=true,k=i=j=0;s[i]!='\0';i++)
        {
            if(flag&&s[i]>='0'&&s[i]<='9')
                w[k][j]='\0',k++,j=0,flag=false;
            else if(!flag&&s[i]>='A'&&s[i]<='Z')
                w[k][j]='\0',k++,j=0,flag=true;
            w[k][j++]=s[i];
        }
        if(k==1)
        {
            for(r=c=i=0;w[0][i]!='\0';i++)
                c=c*26+w[0][i]-'A'+1;
            for(i=0;w[1][i]!='\0';i++)
                r=r*10+w[1][i]-'0';
            printf("R%dC%d\n",r,c);
        }
        else if(k==3)
        {
            for(r=c=i=0;w[3][i]!='\0';i++)
                c=c*10+w[3][i]-'0';
            i=0;
            while(c)
            {
                w[3][i++]=(c-1)%26+'A';
                c=(c-1)/26;
            }
            for(i--;i>=0;i--)
                printf("%c",w[3][i]);
            for(i=0;w[1][i]!='\0';i++)
                r=r*10+w[1][i]-'0';
            printf("%d\n",r);
        }
    }
}
菜鸟成长记
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值