-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoct.cpp
32 lines (30 loc) · 830 Bytes
/
oct.cpp
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
#include <iostream>
#include <string>
using namespace std;
int main()
{
int count,length;
string binary,binary_2,binary_sum,oct;
cin >> binary;
if(binary.length() % 3 != 0) {
count = binary.length() % 3;
for (count; count < 3; count++) binary_2 += "0";
}
binary_sum = binary_2 + binary;
length = binary_sum.length();
for (int i = 0; i <= length;) {
oct.assign(binary_sum,0, 3);
if (!oct.compare("000")) cout << 0;
else if (!oct.compare("001")) cout << 1;
else if (!oct.compare("010")) cout << 2;
else if (!oct.compare("011")) cout << 3;
else if (!oct.compare("100")) cout << 4;
else if (!oct.compare("101")) cout << 5;
else if (!oct.compare("110")) cout << 6;
else if (!oct.compare("111")) cout << 7;
binary_sum.erase(0, 3);
i += 3;
}
cout << endl;
return 0;
}