Ploblem
Eirik drinks a lot of Bingo Cola to help him program faster, and over the years he has burned many unnecessary calories walking all the way to the kitchen to get some. To avoid this he has just bought a small fridge, which is beautifully placed next to his computer. To make it match his fancy big-tower with all its blinking LEDs, it is necessary to style it a bit.
He has bought a weight sensor with a display and a small general purpose programmable chip, to put underneath the fridge. The idea is to make the display show how many litres of Bingo Cola there is in the fridge. To do this he must read a binary register in the sensor, and convert it to a decimal number to be displayed.
Input
The first line of input gives n ≤ 1000, the number of test cases. Then follow n lines with positive numbers represented as 24-bit binary strings (0s and 1s).
Output
For each number, output its decimal representation, without any leading zeros.
Solution
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
|
class Bakjoon {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
Long result=(long) 0;
Long cnt =(long) 1;
for(int i=0;i<n;i++) {
for(int j=23;j>=0;j--) {
result+= Integer.parseInt(arr[j])*cnt;
cnt*=2;
}
System.out.println(result);
cnt=(long)1;
result=(long)0;
}
}
}
|
https://www.acmicpc.net/problem/11104
'Algorithms > BOJ[Java]' 카테고리의 다른 글
[백준/13597번] Tri-du( A Primeira Fase da Maratona de Programação 2015) [Java] (0) | 2019.12.09 |
---|---|
[백준/11319번] Count Me In (CCPC 2015 Division 2) [Java] (0) | 2019.12.09 |
[백준/5988번] 홀수일까 짝수일까 [Java] (0) | 2019.12.09 |
[백준/10669번] 오늘 날짜 [Java] (0) | 2019.12.09 |
[백준/10093번] 숫자 [Java] (0) | 2019.12.09 |