WA on #2
查看原帖
WA on #2
592238
Elairin176楼主2022/11/13 11:48
#include <iostream>
#include <string>
#include <cmath>
#include <cctype>
using namespace std;
int n,a,b,fna;
string s,r,c;
bool isrxcy(string s){
    if(isdigit(s[1])){
        return true;
    }
    return false;
}
int szi(string s){
    int x=0;
    for(int i=0;i<s.length();i++){
        x*=10;
        x+=s[i]-'0';
    }
    return x;
}
string izs(int x){
    string s,s1;
    while(x!=0){
        char a[2]={'0'+x%10};
        s1=a;
        s.insert(0,s1);
        x/=10;
    }
    return s;
}
string rxcytorx(string a,int b){
    string s;
    while(b!=0){
        b--;
        char ca[2]={char(b%26+'A')};
        string bb=ca;
        s.insert(0,bb);
        b/=26;
    }
    return s+a;
}
string rxtorxcy(string a,int b){
    int x=0;
    for(int i=0;i<a.length();i++){
        x*=26;
        x+=a[i]-'A'+1;
    }
    return "R"+izs(b)+"C"+izs(x);
}
int findnumberaddress(){
    for(int i=0;i<s.length();i++){
        if(isdigit(s[i])){
            return i;
        }
    }
    return -1;
}
int main(void){
    cin>>n;
    while(n--){
        cin>>s;
        if(isrxcy(s)){
            r=s.substr(1,s.find("C")-1);
            c=s.substr(s.find("C")+1,s.length()-1-s.find("C"));
            b=szi(c);
            r=rxcytorx(r,b);
        }else{
            fna=findnumberaddress();
            r=s.substr(0,fna);
            c=s.substr(fna,s.length()-r.length());
            a=szi(c); 
            r=rxtorxcy(r,a);
        }
        cout<<r<<endl;
    }
}
2022/11/13 11:48
加载中...