File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
Solved Archive/11005_Base_Converter Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ // HELLO WORLD!
2
+ #include < iostream>
3
+ #include < stack>
4
+ using namespace std ;
5
+
6
+ /*
7
+ MAIN:
8
+ 1. GET input and base
9
+ 2. WHILE: repeat until input becomes 1
10
+ 2.1. DIV input by base
11
+ 2.1.1. quotient becomes input
12
+ 2.1.2. remainder goes to stack
13
+ 3. PUSH 1 into stack
14
+ 4. PRINT stack
15
+ */
16
+ int main () {
17
+ int input;
18
+ int base;
19
+ cin >> input >> base;
20
+
21
+ stack<char > output;
22
+ while (input >= base) {
23
+ char remainder = input % base;
24
+ if (remainder > 9 )
25
+ remainder = ' A' - 10 + remainder;
26
+ else
27
+ remainder = ' 0' + remainder;
28
+ output.push (remainder);
29
+ input = input / base;
30
+ }
31
+ if (input > 9 )
32
+ input = ' A' - 10 + input;
33
+ else
34
+ input = ' 0' + input;
35
+ output.push (input);
36
+
37
+ while (!output.empty ()) {
38
+ cout << output.top ();
39
+ output.pop ();
40
+ }
41
+
42
+ return 0 ;
43
+ }
You can’t perform that action at this time.
0 commit comments