zoukankan      html  css  js  c++  java
  • 1B. Spreadsheets

    题目大意:

    行和列的两种方式。
    A是1, B是2,....Z是26, AA是27, AB是28...........
    如: BC23代表55列23行
    还有一种表示方法:R23C55, 代表23行,55列。
     
    要求这两种数字之间相互转化。
    =========================================================================
    需要注意的就是两点:
    1. 每个数字对26取余数后要再 - 1,再+‘A’ 就是答案了。
    2. 如果余数是0则要对C--,并且输出的字符是Z、
     
     
     
    #include <iostream>
    #include <cmath>
    #include <algorithm>
    #include <string>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cstdlib>
    using namespace std;
    typedef long long LL;
    const LL INF = 0xffffff;
    const int maxn = 201315;
    const LL MOD = 1e9+7;
    void Putt(int C)
    {
        if(C == 0)
            return ;
        if(C%26 == 0)
            Putt((C-1)/26);
        else
            Putt(C/26);
        char ch;
        if(C%26 == 0)
            ch = 'Z';
        else
            ch = C%26 + 'A' - 1;
        printf("%c", ch);
    }
    
    void ChangeOne(char str[])
    {
        int R, C;
        sscanf(str,"R%dC%d", &R, &C);
    
        Putt(C);
        printf("%d
    ", R);
    }
    
    void ChangeTow(char str[])
    {
        int num = 0, i;
        for(i=0; str[i] >= 'A' && str[i] <= 'Z'; i++)
        {
            num = num*26 + str[i] - 'A' + 1;
        }
        printf("R%sC%d
    ",str+i, num);
    }
    bool Ok(char str[])
    {
        if(str[0] == 'R' && str[1] >= '0' && str[1] <= '9')
        {
            for(int i=1; str[i]; i++)
            {
                if(str[i] == 'C')
                    return true;
            }
        }
        return false;
    }
    
    
    int main()
    {
        int T;
        char str[105];
        scanf("%d", &T);
        while(T--)
        {
            cin >> str;
    
            if(Ok(str))
                ChangeOne(str);
            else
                ChangeTow(str);
    
        }
        return 0;
    }
    /*
    26 Z
    27 AA
    53 BA
    BZ 78
    CA 79
    */
  • 相关阅读:
    hello , world Tkinter代码描述
    Tkinter 类
    什么是Tkinter?
    99_恢复二叉搜索树
    总结eclipse中常用好用的快捷键或者自定义一下快捷键:
    封装与职责分离的开发思维
    正在学习的路上
    串比较
    坚持的力量 第二十篇
    串连接
  • 原文地址:https://www.cnblogs.com/chenchengxun/p/4836984.html
Copyright © 2011-2022 走看看