文章标题 CoderForces 1B : Spreadsheets(模拟)

本文介绍了一种表格坐标系统之间的转换方法,包括26进制到10进制的转换及反之亦然,适用于Excel等电子表格软件中不同坐标系统的互换。

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

Spreadsheets

Description
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 Input
Input
2
R23C55
BC23
Output
BC23
R23C55
Source
Codeforces Beta Round #1
题意:就是有两种形式表示行和列,然后当输入一种形式,用另一种形式输出出出来
分析:就是模拟题。26进制和10进制的相互转换
代码:

#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<math.h>
#include<map>
#include<queue> 
#include<algorithm>
using namespace std;
const int inf = 0x3f3f3f3f;
string a;
void R_BC(){
//将R#C#形式转化乘ABC数字 形式
    int len=a.length();
    int hang=0,lie=0;
    int place;
    for (int i=0;i<len;i++){
        if (a[i]=='C'){
            place = i;
//找到分段点
            break;
        }
    }
    int tmp=1;
    for (int i=place-1;i>=1;i--){
        hang+=(a[i]-'0')*tmp;
//将字符型转化成数字
        tmp*=10;
    } 
    tmp=1;
    for (int i=len-1;i>place;i--){
        lie+=(a[i]-'0')*tmp;
        tmp*=10;
    }
    char l[100];
    int cnt=0;
    while (lie){
        int t=lie%26;
        if (t==0) {
            t=26;
            lie--;
        }
        l[cnt++]=t+'A'-1;
//转化成26进制,对应的字母放进 L数组中
        lie/=26;
    }
    l[cnt]='\0';
    reverse(l,l+cnt);
//反转函数,将L翻转一下
    printf ("%s%d\n",l,hang);
//输出
}
void BC_R(){
//将ABC数字 形式转化成R#C#形式
    int len=a.length();
    int hang=0,lie=0;
    int place=len-1;
    for (int i=0;i<len;i++){
        if (a[i]>='0'&&a[i]<='9'){
//找分段点
            place=i;
            break;
        }
    }
    int tmp=1;
    for (int i=place-1;i>=0;i--){
        lie+=(a[i]-'A'+1)*tmp;
//转化成对应的十进制
        tmp*=26;
    }
    tmp=1;
    for (int i=len-1;i>=place;i--){
        hang+=(a[i]-'0')*tmp;
        tmp*=10;
    }
    printf ("R%dC%d\n",hang,lie);
//输出
}
int main ()
{
    int t;
    scanf ("%d",&t);
    while (t--){
        cin>>a;
        int flag=0;
        int len = a.length();
        for (int i=0;i<len;i++){
//判断的哪一种形式
            if (a[i]>='0'&&a[i]<='9'&&a[i+1]>='A'&&a[i+1]<='Z'){
                flag=1;
//代表此时的字符串是R#C#型的
            }
        } 
        if (flag){
            R_BC();
        }
        else {
            BC_R();
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值