CodeForces 1B. Spreadsheets(模拟)

题目链接:http://codeforces.com/problemset/problem/1/B

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

题意:

对换两种不同的表示方法表示行列!

代码如下:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 117;
typedef __int64 LL;
int is_letter(char c)
{
    if(c >= 'A' && c <= 'Z')
        return 1;
    return 0;
}

int is_num(char c)
{
    if(c >='0' && c <='9')
        return 1;
    return 0;
}

int main()
{
    LL t;
    char s[maxn];
    scanf("%I64d",&t);
    getchar();
    while(t--)
    {
        gets(s);
        int len = strlen(s);
        int k = 0;
        for(int i = 0; i < len; i++)
        {
            if(is_letter(s[i]) && is_num(s[i+1]))
            {
                k++;
            }
        }
        if(k == 2)//R23C55形式
        {
            LL i, j;
            LL t1 = 0, t2 = 0;
            for(i = 1; ; i++)
            {
                if(is_num(s[i]))
                    t1 = t1*10+s[i]-'0';
                else
                    break;
            }
            for(j = i+1; j < len; j++)
            {
                if(is_num(s[j]))
                    t2 = t2*10+s[j]-'0';
                else
                    break;
            }
            //printf("t1::%I64d t2::%I64d\n",t1,t2);
            char a[maxn];
            i = 0;
            while(t2)
            {
                LL tt = t2%26;
                a[i++] = tt+'A'-1;
                t2/=26;
                if(tt == 0)//注意
                {
                    t2--;
                    a[i-1] = 'Z';
                }

            }
            for(j = i-1; j >= 0; j--)
            {
                printf("%c",a[j]);
            }
            printf("%I64d\n",t1);
        }
        else//BC23形式
        {
            LL i, j;
            LL t3 = 0, t4 = 0;
            for(i = 0; ; i++)
            {
                if(is_num(s[i]))
                    break;
                t3 = t3*26+(s[i]-'A'+1);
            }
            for(j = i; j < len; j++)
            {
                t4 = t4*10+s[j]-'0';
            }
            printf("R%I64dC%I64d\n",t4,t3);
        }
    }
    return 0;
}

/*
99
R23C55
BC23
R26C78
BZ26
*/
时间: 2024-10-08 10:45:14

CodeForces 1B. Spreadsheets(模拟)的相关文章

Codeforces 1B Spreadsheets

零.题目链接:http://codeforces.com/contest/1/problem/B 一.审题 读完题目,题意清晰.说白了,就是先给了两种坐标形式:Excel表格里面每个单元格的列(字母组合)行(数字)坐标形式(e.g.BC23)与R(Row)XC(Column)Y坐标的形式,然后要求将一种转换成另一种,也就是互相转换. 然后需要转换坐标的数据量:n (1? ≤ n?≤?105) 坐标的数值大小范围:≤ 106 二.思路 首先根据输入的格式,我第一想法就是用vector<string

【Codeforces 1B】Spreadsheets

[链接] 我是链接,点我呀:) [题意] A~Z分别对应了1~26 AA是27依次类推 让你完成双向的转换 [题解] 转换方法说实话特别恶心>_< int转string 得像数位DP一样一位一位地确定每一位是啥. 具体的 1位数可以表示16个数字 2位数又可以表示16*16个数字 根据这个算出来int对应的字符串是多少位数的 然后再一点一点地试出来每一位是多少即可 [代码] import java.io.*; import java.util.*; public class Main { st

B - Spreadsheets CodeForces - 1B

在一些知名的表格处理系统中(比如:excel表格),我们经常用大写的字母来表示列,例如A表示第1列,B表示第2列,第26列用Z来表示,同时第27列我们用AA来表示,第28列我们用AB来表示,第29列我们用AC来表示,AZ表示第52列,ZZ之后我们就需要用3个字母来表示列了. 行的表示比较简单,我们一般用正整数来表示,比如1就表示第1行,5就表示第5行,行和列一起表示成为类似BC23的情况,这个表示在第23行,第55列. 有时候,我们的系统也会用RXCY的格式来表示,X和Y是整数,分别表示行号和列

codeforces 591B Rebranding (模拟)

Rebranding Problem Description The name of one small but proud corporation consists of n lowercase English letters. The Corporation has decided to try rebranding - an active marketing strategy, that includes a set of measures to change either the bra

Codeforces 389B(十字模拟)

Fox and Cross Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Fox Ciel has a board with n rows and n columns. So, the board consists of n × n cells. Each cell contains either a symbol '.', or a s

CodeForces 697B Barnicle 模拟

强行模拟 纪念一下…… 1 #include<stdio.h> 2 #include<iostream> 3 #include<algorithm> 4 #include<math.h> 5 #include<string.h> 6 #include<string> 7 #include<map> 8 #include<vector> 9 #include<queue> 10 #define M(a

CodeForces - 344A Magnets (模拟题)

CodeForces - 344A Magnets Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangula

CodeForces 670E(模拟双向链表)

题意:给你一串合法的括号和当前光标的位置和一些操作,问操作完之后的串是怎么样的 思路:模拟一个双向链表的操作,首先先预处理出配对的括号组,然后模拟即可 #include<bits\stdc++.h> using namespace std; const int maxn = 1e6; struct Node { int l,r; }nodes[maxn]; char s1[maxn],s2[maxn]; int a[maxn],d[maxn]; int main() { int n,m,pos

1B. Spreadsheets

题意:将两种不同表达方式进行转换,即26进制与10进制的转换,特殊的是,比如:26用Z表示,27用AA表示,即没有零. 题目链接:http://codeforces.com/problemset/problem/1/B #include <stdio.h> #include <string.h> char str[100000]; void zhuan1(char str[],int len) { int s1=0; int s2=0; sscanf(str,"R%dC%