zoukankan      html  css  js  c++  java
  • codeforces 1B 模拟

    题目大意:

    给出两种行列位置的表示方法,一个是Excel表示法,一个是(R,C)坐标表示。给出一种表示,输出另外一种表示。
    基本思路:
    模拟,首先判断是哪一种表示法,然后转换成另外一种表示方法;
    我做的时候,在(R,C)表示法转换成excel表示法的时候出了点问题,那个数字转字母的部分不会写了,所以借鉴了网上的代码:
    代码如下:
    //我没有处理好的部分
                    int tot=0;
                    while(N){
                        if(N%26==0){
                            res[tot++]='Z';
                            N=N/26-1;
                        }else{
                            res[tot++]='A'-1+N%26;
                            N=N/26;
                        }
                    }
    
    
    //题解代码:
    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    
    using namespace std;
    
    typedef long long ll;
    const int inf = 0x3f3f3f3f;
    const int maxn = 100000+10;
    
    char str[maxn];
    char res[maxn];
    int main(){
        int n;
        while(scanf("%d",&n)==1){
            while(n--){
                scanf("%s",str);
                int len=strlen(str);
                for(int i=0;i<len;i++){
                    if(str[i]>='a'&&str[i]<='z') str[i]=str[i]-'a'+'A';
                }
                int i=0;
                while(i<len&&isalpha(str[i])){
                    i++;
                }
                while(i<len&&isdigit(str[i])){
                    i++;
                }
                if(i>=len){
                    int C=0,N=0;
                    int id=0;
                    while(id<len&&isalpha(str[id])){
                        C=C*26+str[id]-'A'+1;
                        id++;
                    }
                    while(id<len&&isdigit(str[id])){
                        N=N*10+str[id]-'0';
                        id++;
                    }
                    printf("R%dC%d
    ",N,C);
                }else{
                    int C=0,N=0;
                    int id=1;
                    while(id<len&&isdigit(str[id])){
                        C=C*10+str[id]-'0';
                        id++;
                    }
                    id++;
                    while(id<len&&isdigit(str[id])){
                        N=N*10+str[id]-'0';
                        id++;
                    }
                    int tot=0;
                    while(N){
                        if(N%26==0){
                            res[tot++]='Z';
                            N=N/26-1;
                        }else{
                            res[tot++]='A'-1+N%26;
                            N=N/26;
                        }
                    }
                    for(int i=tot-1;i>=0;i--) printf("%c",res[i]);
                    printf("%d
    ",C);
                }
            }
        }
        return 0;
    }
    

      

  • 相关阅读:
    软件测试职业规划(初版)
    http-server简易的HTTP服务解决数据传输问题
    moco框架的使用
    sublime3安装部署及插件安装
    Tomcat下载部署及解决中文乱码显示
    Linux磁盘管理
    DVWA学习记录 PartⅨ
    DVWA学习记录 PartⅧ
    DVWA学习记录 PartⅦ
    DVWA学习记录 PartⅥ
  • 原文地址:https://www.cnblogs.com/imzscilovecode/p/8197731.html
Copyright © 2011-2022 走看看