zoukankan      html  css  js  c++  java
  • Codeforces 1B

    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.

    Examples
    input
    2
    R23C55
    BC23
    output
    BC23
    R23C55

    题意:给出n个字符串,字符串满足以下两种形式中的随机一种:第一种是一串英文加一串数字,如样例中的BC23,表示表格的行号是23,列号是BC,当然,我们规定A,B,C,...,Z分别表示1,2,3,...,26,AA,AB,AC,...,AZ,BA,...,ZZY,ZZZ,AAAA等由此类推分别代表27,28,29,...,52,53,...我们需要把它改为RxCy的形式,其中x就等于原给定的数字,y是通过字母推算得到的数字;同理,第二种就是第一种的逆操作。求出这n个字符串改变形式后的序列。

    题解:大力模拟一发。。。因为刚开始出现R可能有两种情况,我们判断第二位,如果第二位为字母,那么一定属于题意中描述的第一种操作;否则如果第二位是数字,还可能有两种情况,如果接下来都是数字,属于第一种操作,否则属于第二种操作,大力模拟一发即可。

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 char s[100];
     4 int n,f[6],ans[10];
     5 int main()
     6 {
     7     scanf("%d",&n);
     8     f[0]=1;
     9     for (int i=1;i<=5;++i)
    10     f[i]=f[i-1]*26;
    11     for (int i=1;i<=n;++i)
    12     {
    13         bool flag=0,vis=0;
    14         int a=0,b=0,pos=0;
    15         scanf("%s",s);
    16         int len=strlen(s);
    17         if (s[0]=='R'&&s[1]>='0'&&s[1]<='9')
    18         {
    19             vis=1;
    20             for (int j=1;j<len;++j)
    21             if (s[j]>'9')
    22             {
    23                 pos=j;
    24                 flag=1;
    25                 break;
    26             }
    27             if (!flag)
    28             {
    29                 for (int j=1;j<len;++j)
    30                 b=b*10+s[j]-'0';
    31                 printf("R%dC%d
    ",b,'R'-'A'+1);
    32             }
    33             else
    34             {
    35                 for (int j=1;j<pos;++j)
    36                 a=a*10+s[j]-'0';
    37                 for (int j=pos+1;j<len;++j)
    38                 b=b*10+s[j]-'0';
    39                 int j;
    40                 for (j=1;b>=f[j];b-=f[j],++j);
    41                 if(b==0)
    42                 {
    43                     j--;
    44                     while (j--) printf("Z");
    45                 }
    46                 else
    47                 {
    48                     --b;
    49                     for (int k=1;k<=j;++k)
    50                     {
    51                         ans[k]=b%26;
    52                         b/=26;
    53                     }
    54                     for (int k=j;k;--k)
    55                     printf("%c",ans[k]+'A');
    56                 }
    57                 printf("%d
    ",a);
    58             }
    59         }
    60         if (!vis)
    61         {
    62             for (int j=0;j<len;++j)
    63             if (s[j]>='0'&&s[j]<='9')
    64             {
    65                 if (!pos) pos=j;
    66                 break;
    67             }
    68             printf("R");
    69             for (int j=pos;j<len;++j)
    70             printf("%c",s[j]);
    71             int sum=0;
    72             for (int j=1;j<pos;++j)
    73             sum+=f[j];
    74             for (int j=0;j<pos;++j)
    75             sum+=f[pos-j-1]*(s[j]-'A');
    76             ++sum;
    77             printf("C%d
    ",sum);
    78         }
    79     }
    80     return 0;
    81 }
    View Code
  • 相关阅读:
    文本设置超过几行显示...
    CSS内置的几个标准的伪类和伪对象
    正则替换URL地址为链接地址
    移动端某些机型touchend事件触发鸡肋
    zepto 扩展prevAll(),nextAll()方法
    火狐下window.event获取undefined问题
    哪些情况下margin-left和padding-left无效?
    兵部-2048
    HTML5 将成为 HTML、XHTML 以及 HTML DOM 的新标准。HTML 的上一个版本诞生于 1999 年。自从那以后,Web 世界已经经历了巨变。HTML5 仍处于完善之中。然而,大部分现代浏览器已经具备了某些 HTML5 支持。
    二分查找
  • 原文地址:https://www.cnblogs.com/zk1431043937/p/7593130.html
Copyright © 2011-2022 走看看