잡다로그

[Python/코테] 백준 2577번 숫자의 개수 본문

Algorithm

[Python/코테] 백준 2577번 숫자의 개수

날으는다람쥐 2023. 11. 8. 18:26

2577 숫자의 개수

문제 및 조건 설명: https://www.acmicpc.net/problem/2577

 

a = int(input())
b = int(input())
c = int(input())

result = [0] * 10

multiple = a * b * c

for i in list(str(multiple)):
    result[int(i)] += 1

for i in result:
    print(i)

나다어

  • 특정 배열/범위를 순회하며 검색해야 하는 경우, 인덱스를 적극 활용하자.
  • 파이썬의 str() 함수는 정수를 문자열로 바꿔주는 연산이다.
  • input()은 한 줄의 입력값을 받는 함수이다.

같은 로직이지만, 변수를 더 간단화한 풀이로는 아래와 같이 쓸 수 있다.

a = int(input())
b = int(input())
c = int(input())

d = a*b*c
d = str(d)
for i in range(10):
    print(d.count(str(i)))

출처: https://www.acmicpc.net/source/53975405

 

혹은 더 간단하게 아래와 같이 쓸 수 있다.

prod = int(input())*int(input())*int(input())
for i in range(10):
    print(str(prod).count(str(i)))

출처: https://www.acmicpc.net/source/54582232

Comments