codeforces 1B Spreadsheets

codeforces 1B Spreadsheets

题意:类似Excel,对每个表格的位置有两种表示方法,现在给出任一种,输出该位置的另一种表示方法。

样例:

**Input**
2
R23C55
BC23
**Output**
BC23
R23C55

思路:第一个点在于判断给出的表示是法一还是法二;然后只需分情况转化坐标就行了。

以下是AC代码:

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cmath>
#include<cctype>
#include<cstring>
#include<string>  
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll; 
const int INF = 1 << 29;

void solve1(string s, int b){
    //R23C55
    int tem = 0;
    string ans;
    for(int i = b+1; i < s.size(); i++){
        tem = tem * 10 + s[i] - '0';
    }
    vector<char> v;
    while(tem > 0){
        tem --;
        v.push_back((tem%26) + 'A');
        tem /= 26;
    }
    reverse(v.begin(), v.end());
    for(int i = 0; i < v.size(); i ++){
        cout << v[i];
    }
    for(int i = 1; i < b; i ++){
        cout << s[i];
    }
    cout << endl;
}
void solve2(string s){
    // BC23
    int b = INF;
    cout << "R";
    int ans = 0;
    for(int i = 0; i <s.size(); i ++){
        if(isdigit(s[i])) {
            cout << s[i];
            b = min(b, i);  
        }
    }
    for(int i = 0; i < b; i ++){
        ans *= 26;
        ans += (s[i] - 'A' + 1);
    }
    cout << "C" << ans << endl;
}
void solve(string s){
    for(int i = 1; i < s.size(); i ++){
        if(s[i] == 'C' && isdigit(s[i-1])){
            solve1(s, i);
            return ;
        }
    }
    solve2(s);
    return ;
}

int main(){
    int t;
    string s;
    cin >> t;
    while(t--){
        cin >> s;
        solve(s);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值