[파이썬][백준 11104번] Fridge of Your Dreams
1. 문제Permalink
[Bronze I] Fridge of Your Dreams - 11104Permalink
성능 요약Permalink
메모리: 30840 KB, 시간: 144 ms
분류Permalink
구현(implementation), 수학(math)
문제 설명Permalink
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.
입력Permalink
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).
출력Permalink
For each number, output its decimal representation, without any leading zeros.
출처: 백준, https://https://www.acmicpc.net/
2. 해결방법 시간복잡도Permalink
- 단순 코딩 O(N)
3. 문제 해결 및 코드Permalink
A = int(input()) # 26 | |
B = A # 26 | |
cnt = 0 # 0 | |
while True: | |
a = B // 10 # 2 6 8 4 | |
b = B % 10 # 6 8 4 2 | |
c = (a + b) % 10 # 8 4 2 6 | |
B = (b * 10) + c # 68 84 42 26 | |
cnt += 1 # 1 2 3 4 | |
if (B == A): | |
break | |
print(cnt) # 4 |
-
주석을 참고하면서 이해를 돕습니다.Permalink
4. 알고리즘 및 해설Permalink
- 문제의 요점은 받은 값도 2진수로 변경해서 출력하는 것이다.
- 반복문을 통해 해당 값을 계속 받아서 출력해준다.