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 the
#include
using namespace std;
string toExcelColumn(int col) { string result = ""; while (col > 0) { int rem = (col - 1) % 26; result = char('A' + rem) + result; col = (col - 1) / 26; } return result; }
pair<int, int> fromExcelColumn(const string& col) { int result = 0; int multiplier = 1; for (int i = col.length() - 1; i >= 0; i--) { result += (col[i] - 'A' + 1) * multiplier; multiplier *= 26; } return make_pair(result, 0); }
string toRXCY(int row, int col) { return "R" + to_string(row) + "C" + to_string(col); }
pair<int, int> fromRXCY(const string& cell) { int r_pos = cell.find('R'); int c_pos = cell.find('C'); int row = stoi(cell.substr(r_pos + 1, c_pos - r_pos - 1)); int col = stoi(cell.substr(c_pos + 1)); return make_pair(row, col); }
int main() {
int n;
cin >> n;
vector
for (int i = 0; i < n; i++) {
if (coordinates[i][0] == 'R' && isdigit(coordinates[i][1])) {
pair<int, int> cell = fromRXCY(coordinates[i]);
cout << toExcelColumn(cell.second) << cell.first << endl;
} else {
pair<int, int> cell = fromExcelColumn(coordinates[i]);
cout << toRXCY(cell.second, cell.first) << endl;
}
}
return 0;
原文地址: http://www.cveoy.top/t/topic/h8ON 著作权归作者所有。请勿转载和采集!