Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 나머지
- 2884
- 기찍 N
- A+B - 5
- A+B - 8
- 수학
- BOJ
- 14681
- 8958
- 10998
- A+B - 3
- 두 수 비교하기
- 2739
- 2742
- 숫자의 개수
- X보다 작은 수
- A×B
- 사칙연산
- 별 찍기 - 2
- 10871
- 빠른 A+B
- A+B - 7
- 별 찍기 - 1
- 구현
- N 찍기
- 사분면 고르기
- A/B
- 3052
- 2741
- Python
Archives
- Today
- Total
RIRINTO's Blog
BOJ 2577: 숫자의 개수 (Python) 본문
2577번: 숫자의 개수
첫째 줄에 A, 둘째 줄에 B, 셋째 줄에 C가 주어진다. A, B, C는 모두 100보다 크거나 같고, 1,000보다 작은 자연수이다.
www.acmicpc.net
첫째 줄에 A, 둘째 줄에 B, 셋째 줄에 C를 입력받고 세 수를 모두 곱한 후, 0 ~ 9의 숫자가 몇 개 포함되어있는지 차례로 출력합니다.
더보기
각 자리의 수를 카운트하여 결과를 구할 수 있습니다.
A = int(input())
B = int(input())
C = int(input())
product = A * B * C
numbers = {}
while product:
numbers[product % 10] = numbers.get(product % 10, 0) + 1
product = product // 10
for i in range(10):
print(numbers.get(i, 0))
collections 라이브러리의 Counter를 사용하여 더욱 쉽게 구할 수 있습니다.
from collections import Counter
A = int(input())
B = int(input())
C = int(input())
product = A * B * C
numbers = Counter(map(int, list(str(product))))
for i in range(10):
print(numbers.get(i, 0))
물론 str 자료형을 거치지 않고도 표현이 가능하죠.
from collections import Counter
def counter(num):
arr = []
while num:
arr.append(num % 10)
num = num // 10
return arr
A = int(input())
B = int(input())
C = int(input())
numbers = Counter(counter(A * B * C))
for i in range(10):
print(numbers.get(i, 0))
'BOJ' 카테고리의 다른 글
BOJ 1546: 평균 (Python) (0) | 2021.09.19 |
---|---|
BOJ 3052: 나머지 (Python) (0) | 2021.09.19 |
BOJ 2562: 최댓값 (Python) (0) | 2021.09.19 |
BOJ 10818: 최소, 최대 (Python) (0) | 2021.09.19 |
BOJ 1110: 더하기 사이클 (Python) (0) | 2021.09.19 |
Comments