Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- void numberToLetters(int n)
- {
- char str[11];
- int i = 0;
- while (n > 0) {
- int remainder = n % 26;
- if (remainder == 0) {
- str[i++] = 'Z';
- n = (n / 26) - 1;
- }
- else
- {
- str[i++] = (remainder - 1) + 'A';
- n = n / 26;
- }
- }
- str[i] = '\0';
- reverse(str, str + strlen(str));
- cout << str << endl;
- return;
- }
- int lettersToNumber(string inputString)
- {
- int result = 0;
- for (const auto& c : inputString)
- {
- result *= 26; // 0 // 26 //
- result += c - 'A' + 1; //A // A
- // AAC
- // cout << "c: " << c << endl;
- }
- return result;
- }
- int main()
- {
- int broiTestove =0;
- cin >> broiTestove;
- cin.ignore();
- string input;
- while(broiTestove--)
- {
- getline(cin, input);
- char check = input.at(0);
- int checkInt = check;
- if(checkInt>57)
- {
- // cout << "chars"<< endl;
- int result = lettersToNumber(input);
- cout << result << endl;
- }
- else {
- int currentNum = atoi(input.c_str());
- numberToLetters(currentNum);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment