codeforces B. Spreadsheets 计算excel的行列
2014-05-01 16:55
211 查看
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA,
28 — AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.
The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23.
Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example.
Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system.
Input
The first line of the input contains integer number n (1 ≤ n ≤ 105),
the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there
are no cells with the column and/or the row numbers larger than 106 .
Output
Write n lines, each line should contain a cell coordinates in the other numeration system.
Sample test(s)
input
output
没想到这道题看起来这么简单,要写出无Bug的程序居然这么麻烦,要处理挺多情况的。
如:
1 判断是什么格式,然后转到相应的转换
2 26进制和10进制互相转换,如何处理
3 26进制还不是从0开始的,要如何处理
对应这里分了四个函数,应该都很清晰了。
28 — AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.
The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23.
Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example.
Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system.
Input
The first line of the input contains integer number n (1 ≤ n ≤ 105),
the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there
are no cells with the column and/or the row numbers larger than 106 .
Output
Write n lines, each line should contain a cell coordinates in the other numeration system.
Sample test(s)
input
2 R23C55 BC23
output
BC23 R23C55
没想到这道题看起来这么简单,要写出无Bug的程序居然这么麻烦,要处理挺多情况的。
如:
1 判断是什么格式,然后转到相应的转换
2 26进制和10进制互相转换,如何处理
3 26进制还不是从0开始的,要如何处理
对应这里分了四个函数,应该都很清晰了。
#pragma once #include <assert.h> #include <math.h> #include <algorithm> #include <utility> #include <queue> #include <deque> #include <vector> #include <string> #include <iostream> using namespace std; string RCtoABC(string &rc) { string num; unsigned i = 1; for ( ; i < rc.size() && rc[i] != 'C'; i++) { num.push_back(rc[i]); } string abc; int a = 0; for (i++; i < rc.size(); i++) { a = a * 10 + rc[i] - '0'; } while (a) { int b = (a - 1) % 26;//注意这里的转换方法 a = (a - 1) / 26; abc.push_back(b + 'A'); } reverse(abc.begin(), abc.end()); return abc+num; } pair<int, string> ABCtoRC(string &abc) { unsigned i = 0; int rnum = 0; for ( ; i < abc.size(); i++) { if (abc[i] < 'A' || 'Z' < abc[i]) break; rnum = rnum * 26 + (abc[i] - 'A' + 1);//注意+1 } return pair<int, string>(rnum, abc.substr(i)); } bool isRC(string &s) { if (s[0] != 'R') return false; unsigned i = 1; for ( ; i < s.size() && 'A' <= s[i] && s[i] <= 'Z'; i++);//注意判断,如RC12 for ( ; i < s.size() && '0' <= s[i] && s[i] <= '9'; i++); if (i >= s.size() || s[i] != 'C') return false; return true; } void Spreadsheets() { int n; cin>>n; string s; while (n--) { cin>>s; if (isRC(s)) { cout<<RCtoABC(s)<<endl; } else { pair<int, string> pis = ABCtoRC(s); cout<<'R'<<pis.second<<'C'<<pis.first<<endl; } } }
相关文章推荐
- codeforces B Spreadsheets
- codeforces——B. Spreadsheets
- Codeforces Spreadsheets
- Codeforces Beta Round #1 B Spreadsheets
- Codeforces Gym 101505C : Cable Connection (计算几何)
- Codeforces Round #401 (Div. 2) C. Alyona and Spreadsheet(暴力)
- Educational Codeforces Round 2D. Area of Two Circles' Intersection(计算几何+圆相交的面积)
- 【Codeforces Round 335 (Div 2)E】【计算几何-凸包 线性规划 三分凸包上最优点】Freelancer's Dreams 二维属性 充最少的钱变得满足要求 [计算几何-凸包模
- Codeforces Round #335 (Div. 1) C. Freelancer's Dreams 计算几何
- 【Codeforces Round 339 (Div 2)C】【计算几何 点到直线的距离模板】Peter and Snow Blower 多边形整体绕一圆心旋转的运行面积
- Codeforces Gym 100733A Shitália 计算几何
- Codeforces Beta Round #1 C. Ancient Berland Circus (计算几何)
- Codeforces Gym-101617F Move Away [计算几何]
- Codeforces Gym 100286A. Aerodynamics 计算几何 求二维凸包面积
- Codeforces Gym 100523K K - Cross Spider 计算几何,判断是否n点共面
- Codeforces Round #346 (Div. 2)(D)计算几何
- Creating Excel Spreadsheets with Office Web Components (OWC) By Scott Mitchell
- 【Codeforces Round 323 (Div 2)A】【水题】Asphalting Roads 行列之进行首次操作
- Creating Spreadsheets and Charts in Microsoft Office Excel 2007 for Windows: Visual QuickProject Gui
- Codeforces Round #284 (Div. 1) A. Crazy Town 计算几何