-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1212.cpp
More file actions
52 lines (49 loc) · 725 Bytes
/
Copy path1212.cpp
File metadata and controls
52 lines (49 loc) · 725 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
46
47
48
49
50
51
52
// 1212. 8진수 2진수
// 2019.05.14
// 진법
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s;
cin >> s;
string ans;
// 각 자릿수에 대해 8진수->2진수로 변환
for (int i = 0; i < s.size(); i++)
{
int k = s[i] - '0';
string tmp;
for (int j = 0; j < 3; j++)
{
if (k % 2 == 0)
{
tmp += '0';
}
else
{
tmp += '1';
}
k /= 2;
}
for (int j = 2; j >= 0; j--)
{
ans += tmp[j];
}
}
// 맨앞에 나오는 0들을 제거하기 위한 작업
int index = 0;
for (int i = 0; i < ans.size()-1; i++)
{
if (ans[i] == '0')
{
index++;
}
else
{
break;
}
}
cout << ans.substr(index, ans.size()) << endl;
return 0;
}