Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- bool isdg(string s)
- {
- for (int i = 0; i < s.length(); i++)
- {
- if (!isdigit(s[i]))
- return false;
- }
- return true;
- }
- int main()
- {
- int tests;
- cin >> tests;
- string input;
- while (tests--)
- {
- cin >> input;
- int str_len = input.length();
- int r_pos = input.find('R');
- int c_pos = input.find('C');
- if (c_pos != -1 && r_pos != -1 && c_pos > 1 && isdg(input.substr(1, c_pos - 1)))
- {
- int row_num = stoi(input.substr(1, c_pos - 1));
- int col_num = stoi(input.substr(c_pos + 1));
- string result = "";
- while (col_num > 0)
- {
- int index = (col_num - 1) % 26;
- result = (char)(index + 'A') + result;
- col_num = (col_num - 1) / 26;
- }
- cout << result << row_num << endl;
- }
- else
- {
- int row_num_index = 0;
- for (int i = 0; i < str_len; i++)
- {
- if (isdigit(input[i]))
- {
- row_num_index = i;
- break;
- }
- }
- string col_letters = input.substr(0, row_num_index);
- int result = 0;
- for (int i = 0; i < col_letters.length(); i++)
- {
- result *= 26;
- result += col_letters[i] - 'A' + 1;
- }
- row_num_index = stoi(input.substr(row_num_index, str_len - row_num_index));
- cout << "R" << row_num_index << "C" << result << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement