您的位置:首页 > 其它

codeforces 1B Spreadsheets

2016-08-23 17:38 393 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ACM codeforces 水题