상세 컨텐츠

본문 제목

(Python) 횟수 세는 문제

Python/Coding weight lightening

by 코딩하는 낙타 2020. 1. 4. 15:41

본문

https://www.acmicpc.net/problem/2577

 

2577번: 숫자의 개수

첫째 줄에 A, 둘째 줄에 B, 셋째 줄에 C가 주어진다. A, B, C는 모두 100보다 같거나 크고, 1,000보다 작은 자연수이다.

www.acmicpc.net

내 풀이:

1
2
3
4
5
6
7
8
9
10
11
12
a=int(input())
b=int(input())
c=int(input())
D=str(a*b*c)
n=len(D)
answer=[0,0,0,0,0,0,0,0,0,0]
cnt=0
for i in range(n):
    cnt=int(D[i])
    answer[cnt]+=1
for i in range(10):
    print(answer[i])
 

이와 같이 횟수를 저장할 리스트를 만들어 정답지를 만들려는 습관이 있다.

 

apiacere님 풀이:

1
2
3
4
5
6
= int(input())
= int(input())
= int(input())
= list(map(int, (str(a * b * c))))
for i in range(10):
    print(d.count(i))
 

count() 를 이용하여 원하는 값의 횟수를 직접 출력하도록 해야한다.

'Python > Coding weight lightening' 카테고리의 다른 글

(Python) 소수 구하기  (0) 2020.01.08
(Python) 출력  (0) 2020.01.03
(Python) 입력  (0) 2020.01.03

관련글 더보기

댓글 영역