반응형
Notice
Recent Posts
Recent Comments
Link
안경잡이 구루루
백준 2577 ( 숫자의 개수 ) [ Python ] 본문
반응형
나:
a = int(input())
b = int(input())
c = int(input())
100 <= a < 1000 and 100 <= b< 1000 and 100 <= c < 1000
result = str(a*b*c)
for i in range(0,10):
print(result.count(str(i)))
완성된 코드는 위와 같다.
a = int(input())
b = int(input())
c = int(input())
100 <= a < 1000 and 100 <= b< 1000 and 100 <= c < 1000
입력값 3개를 a,b,c로 받고 그것들의 조건에 따라 범위를 설정
result = str(a*b*c)
for i in range(0,10):
print(result.count(str(i)))
입력값 3개를 모두 곱합 값을 result 변수에 저장. 문제는 0 - 9까지 result에서 개수를 세서 출력해야 한다.
그래서 count함수 사용하기 위해 str 형태로 result를 저장해 0 - 9 까지 각각의 문자로 개수를 센다.
count( x ) -> x의 요소가 몇개있는지 돌려주는 함수
for 반복문을 이용해서 위 방법을 실현할 수 있다.
반응형