-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha304.cpp
More file actions
37 lines (32 loc) · 765 Bytes
/
a304.cpp
File metadata and controls
37 lines (32 loc) · 765 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
/*
Date: 10/1/2020
Author: ELV
Question: https://zerojudge.tw/ShowProblem?problemid=a034
Decimal to Binary converter.
* Output must be LONG type.
*/
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int input;
while(cin >> input)
{
long output=0;
short temp=0;
// 當被 2 除過後的商大於 1 表示可以繼續進行
while(input/2 >= 1)
{
output = output + ((input % 2) * pow(10, temp));
input = input / 2;
temp++;
}
if(input == 1)
{
output = output + ((input % 2) * pow(10, temp));
}
cout << output << endl;
}
return 0;
}