C++
124나라 - 코장모 스터디 4 [Programmers 코딩 테스트 연습]
류수 Ryusu
2019. 10. 2. 17:21
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
53
54
55
|
// 124나라
#include <iostream>
#include <string>
using namespace std;
string OTF(int n); // 124
void main()
{
int n;
while (1)
{
cout << "숫자 입력 : ";
cin >> n;
if (n > 500000000 || n < 0)
break;
cout << OTF(n) << endl;
}
}
string OTF(int n)
{
string arr[] = { "4", "1", "2" };
int n1 = n;
int n2;
string n123 = "";
while (n > 0)
{
n2 = n % 3;
n = n / 3; //n을 3으로 나눈 몫
if (n2 == 0)
n--;
n123 = arr[n2] + n123;
//if (n2 == 0)
//{
// n--;
//}
//else if(n1 >= 3) //몫이 3보다 큼
//{
// n2 = n % 3;
// n1 = n1 / 3;
// n123 = arr[n1] + n123;
//}
}
return n123;
}
|
cs |