codeforces--Spreadsheets(模拟)

Spreadsheets

Time Limit:10000MS     Memory Limit:65536KB     64bit IO Format:%I64d
& %I64u

Submit Status

Appoint description: 
System Crawler  (2015-01-06)

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

在两种格式之间转换,先处理处了1到1000000的对应字母表示,对于字母转换为数字的时候使用二分

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
char str[1000010][6] ;
int num[1000010] , low[10] , mid , high[10] ;
char s[1000] ;
int serch(char *s,int i)
{
    int l = low[i] , m , h = high[i] , k ;
    while( l <= h )
    {
        m = ( l + h ) / 2 ;
        k = strcmp(s,str[m]) ;
        if( k == 0 )
            return m ;
        if( k < 0 )
            h = m - 1 ;
        else
            l = m + 1 ;
    }
}
void init()
{
    int i , j , temp ;
    str[1][0] = 'A' ; str[1][ num[1] ] = '\0' ;
    num[1] = 1 ;
    low[1] = 1 ;
    for(i = 1 ; i <= 1000000 ; i++)
    {
        temp = 1 ;
        num[i] = num[i-1] ;
        for(j = num[i-1]-1 ; j >= 0 ; j--)
        {
            temp += (str[i-1][j] - 'A'+1) ;
            if( temp >= 27 )
            {
                str[i][j] = temp - 27 + 'A' ;
                temp = 1 ;
            }
            else
            {
                str[i][j] = temp - 1 + 'A' ;
                temp = 0 ;
            }
        }
        if( temp )
        {
            num[i]++ ;
            for(j = num[i]-1 ; j > 0 ; j--)
                str[i][j] = str[i][j-1] ;
            str[i][0] = 'A' ;
            high[ num[i-1] ] = i-1 ;
            low[ num[i] ] = i ;
        }
        str[i][ num[i] ] = '\0' ;
    }
    high[ num[1000000] ] = 1000000 ;
}
int main()
{
    int t , x , y , l , i , j ;
    init() ;
    scanf("%d", &t) ;
    while( t-- )
    {
        scanf("%s", s) ;
        l = strlen(s) ;
        for(i = 0 ; i < l ; i++)
            if( s[i] >= '0' && s[i] <= '9' )
                break ;
        for(  ; i < l ; i++)
            if( s[i] >= 'A' && s[i] <= 'Z' )
                break ;
        if( i < l )
        {
            //RC
            x = 0 ; y = 0 ;
            for(i = 1 ; i < l ; i++)
            {
                if( s[i] == 'C' )
                    break ;
                x = x * 10 + s[i] - '0' ;
            }
            for(i++ ; i < l ; i++)
                y = y * 10 + s[i] - '0' ;
            printf("%s%d\n", str[y], x);
        }
        else
        {
            x = 0 ; y = 0 ;
            for(i = 0 ; i < l ; i++)
                if( s[i] >= '0' && s[i] <= '9' )
                    break ;
            for(j = i ; j < l ; j++)
                x = x * 10 + s[j] - '0' ;
            s[i] = '\0' ;
            y = serch(s,i) ;
            printf("R%dC%d\n", x, y) ;
        }
    }

    return 0;
}
时间: 2024-10-10 06:00:16

codeforces--Spreadsheets(模拟)的相关文章

CodeForces - 427B (模拟题)

Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of t

CodeForces - 404B(模拟题)

Marathon Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose

Codeforces 452D [模拟][贪心]

题意: 给你k件衣服处理,告诉你洗衣机烘干机折叠机的数量,和它们处理一件衣服的时间,要求一件衣服在洗完之后必须立刻烘干,烘干之后必须立刻折叠,问所需的最小时间. 思路: 1.按照时间模拟 2.若洗完的衣服或者烘干的衣服较多来不及进行下一个步骤,则从一开始就顺延洗衣服的时间,贪心的思想也是体现在这里. 3.关键在于烘干衣服的顺延如何处理,因为需要调整洗衣服的起始时间,其实我们只要对烘干衣服的时间进行顺延处理就可以了,因为即使没有调整洗衣服的起始时间,那么下次到了烘干衣服的时间的时候因为烘干衣服的数

CodeForces - 404A(模拟题)

Valera and X Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the Engli

CodeForces - 200ACinema模拟题

CodeForces - 200A Cinema Time Limit: 1500MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description The capital of Berland has the only movie theater in the country. Besides, it consists of only one room. The room is divid

【题解】Berland.Taxi Codeforces 883L 模拟 线段树 堆

Prelude 题目传送门:ヾ(?ω?`)o Solution 按照题意模拟即可. 维护一个优先队列,里面装的是正在运营中的出租车,关键字是乘客的下车时间. 维护一个线段树,第\(i\)个位置表示第\(i\)个房子前面有没有停放出租车,这样在有人需要打车的时候可以快速找到离她最近的车的位置. 对每个房子维护一个堆,里面装的是停在这个房子前面的出租车,关键字是出租车的编号和上一个乘客下车的时间,上一个乘客下车越早,等待时间越长. 然后模拟时间的流逝就可以了,代码非常好写. Code #includ

CodeForces - 864C-Bus-(模拟加油站问题)

https://vjudge.net/problem/CodeForces-864C 题意:两地之间有个加油站,往返走k个单程,最少加油多少次. 大佬几十行代码就解决,我却要用一百多行的if语句模拟解决. #include<stdio.h> #include<iostream> #include<algorithm> #include<cstring> #include<math.h> #include<string> #includ

Codeforces 703B (模拟) Mishka and trip

题目:这里 题意:n个城市,每个城市有个魅力值vi,首先,有n条路将这n个城市连成一个环,1号城市连2号城市,2号连3号****n号连1号城市,每条路的魅力值是其连接的两个城市 的魅力值的乘积,这n个城市其中还有k个是特殊城市,每个特殊城市和任意一条城市都有一条路连接,看题目下面的图,保证每两个城市之间最多只有一条路,问所有路的 魅力值之和是多少? 首先是连接成环的路线魅力值,很好算,然后每个特殊城市的路线,先求出所有城市的魅力值之和sum,依次求特殊城市的时候用sum减去这个特殊城市本身以及两

CodeForces 373B——模拟——Making Sequences is Fun

We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For example, S(893) = 3,S(114514) = 6. You want to make a consecutive integer sequence starting from number m (m, m + 1, ...). But you need to pay 

CSU-ACM暑假集训基础组训练赛(4)解题报告

•Problem A SPOJ SUB_PROB   AC自动机 •题意: 给定一个长为M(M≤100000 )的文本串,和N(N≤1000)个长度不超过2000的模式串,问每个模式串是否在文本串中出现过? •几乎和周一课件上的第一个例题一模一样.. •把文本串丢到AC自动机里面去跑. •注意: •1.可能有两个相同的模式串(略坑吧.) •2.一个模式串可能是另一个模式串的后缀,即如果一个点的fail指针指向的点是一个“危险节点”,那么它本身也是一个“危险节点”. 1 #include <ios