-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpreadsheetColumnEncoding.cpp
More file actions
45 lines (37 loc) · 991 Bytes
/
SpreadsheetColumnEncoding.cpp
File metadata and controls
45 lines (37 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
//#include <vector>
//#include <string>
//#include <algorithm>
using namespace std;
int DecimalToOtherBase(const string & num, int n, int base)
{
bool is_negative = (num[0] == '-' ? 1: 0);
int StringToNum = 0, digit; string NumToString[32];
for (int i = is_negative; i < num.size(); i++)
{
digit = num[i] - '0';
StringToNum = StringToNum *10 + digit;
}
cout << "StringToNum " << StringToNum << endl;
n = StringToNum;
int tempVec[32];
int i = 0;
while (n > 0)
{
tempVec[i] = n % base;
if (n % base == 0) { NumToString[i] = + (char)('Z'); n = n-1; }
else{ NumToString[i] = + (char)(n % base + 'A'-1); }
n = n /base;
i++;
}
for (int j = i - 1; j >= 0; j--)
cout << NumToString[j] << " " << tempVec[j] << endl;
cout << endl;
return n;
}
int main()
{
int num = 702, base = 26; string mynumber = "449";
cout << DecimalToOtherBase(mynumber, num, base) << endl;
return 0;
}