https://www.acmicpc.net/problem/12791
12791번: Starman
첫 번째 줄에 질의의 수 정수 Q(Q ≤ 100)가 주어진다. 이후 Q개의 줄에 질의 S, E(1 ≤ S ≤ E ≤ 2016)가 정수로 주어진다.
www.acmicpc.net
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
31
32
33
34
35
36
37
38
39
40
41
42
|
def sol(album,s,e):
cnt = 0
answer=[]
for i in album:
if i[0]>=s and i[0]<=e:
cnt+=1
answer.append(i)
elif i[0]>e:
break
print(cnt)
for i in answer:
print(i[0],i[1])
if __name__ == '__main__':
bowie = [[1967, 'DavidBowie'],
[1969, 'SpaceOddity'],
[1970, 'TheManWhoSoldTheWorld'],
[1971, 'HunkyDory'],
[1972, 'TheRiseAndFallOfZiggyStardustAndTheSpidersFromMars'],
[1973, 'AladdinSane'],
[1973, 'PinUps'],
[1974, 'DiamondDogs'],
[1975, 'YoungAmericans'],
[1976, 'StationToStation'],
[1977, 'Low'],
[1977, 'Heroes'],
[1979, 'Lodger'],
[1980, 'ScaryMonstersAndSuperCreeps'],
[1983, 'LetsDance'],
[1984, 'Tonight'],
[1987, 'NeverLetMeDown'],
[1993, 'BlackTieWhiteNoise'],
[1995, '1.Outside'],
[1997, 'Earthling'],
[1999, 'Hours'],
[2002, 'Heathen'],
[2003, 'Reality'],
[2013, 'TheNextDay'],
[2016, 'BlackStar']]
t= int(input())
for i in range(t):
s ,e =map(int,input().split())
sol(bowie,s,e)
|
cs |
예제 2번 데이터 보고 반복, 조건문으로 구현하시면 됩니당
Check example 2 data, Use Loop, IF clause
반응형
'python-algorithm' 카테고리의 다른 글
백준 12833 XORXORXOR (0) | 2022.11.14 |
---|---|
백준 15947 아기 석환 뚜루루 뚜루 (0) | 2022.11.14 |
백준 16171 나는 친구가 적다 (Small) (0) | 2022.11.13 |
백준 17202 핸드폰 번호 궁합 (0) | 2022.11.13 |
백준 1524 세준세비 (0) | 2022.11.13 |
댓글