codeforces 1B Spreadsheets
2016-08-23 17:38
393 查看
codeforces 1B Spreadsheets
题意:类似Excel,对每个表格的位置有两种表示方法,现在给出任一种,输出该位置的另一种表示方法。
样例:
思路:第一个点在于判断给出的表示是法一还是法二;然后只需分情况转化坐标就行了。
以下是AC代码:
题意:类似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; }
相关文章推荐
- Codeforces 1B Spreadsheets
- CodeForces 1B Spreadsheets
- codeforces 486B OR in Matrix
- codeforces 617e
- CodeForces 385E
- Codeforces 763B 想法
- codeforces 834 C The Meaningless Game
- CodeForces - 194C Cutting Figure (dfs)
- CodeForces 377B Preparing for the Contest
- CodeForces 166'E
- CodeForces 534C
- CF Round#396D (Div. 2)(Codeforces 766D) 简单并查集+map
- CodeForces 834A The Useless Toy
- CodeForces 403 D.Beautiful Pairs of Numbers(组合数学+dp)
- codeforces 101 B. Buses
- Codeforces 617E ( 莫队算法 Mo's algorithm )
- Codeforces 66 D Petya and His Friends(找规律)
- codeforces 766D Mahmoud and a Dictionary
- CodeForces - 426A. The Useless Toy
- CodeForces 459 C.Pashmak and Buses(构造)