์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ/ํŒŒ์ด์ฌ

[๋ฐฑ์ค€ ํŒŒ์ด์ฌ] ๋‹จ๊ณ„๋ณ„๋กœ ํ’€์–ด๋ณด๊ธฐ - Lv4. 1์ฐจ์› ๋ฐฐ์—ด

HHRR 2023. 5. 8. 05:52

# 10807 ๊ฐœ์ˆ˜ ์„ธ๊ธฐ

N=int(input())
x = list(map(int,input().split()))
v = int(input())

print(x.count(v))

- x.count(v)๋กœ x๋ฆฌ์ŠคํŠธ ์•ˆ์— v๊ฐ€ ๋ช‡ ๊ฐœ ๋“ค์–ด๊ฐ€์žˆ๋Š”์ง€ ํ™•์ธ๊ฐ€๋Šฅ

 

# 10871 X๋ณด๋‹ค ์ž‘์€ ์ˆ˜

N,X = map(int,input().split())
A = list(map(int, input().split()))

for i in range(N) :
    if A[i]<X :
        print(A[i], end=" ")

# 10818 ์ตœ์†Œ, ์ตœ๋Œ€

import math
N = int(input())
A = list(map(int, input().split()))

print(min(A),max(A))

- ์ตœ์†Œ min(), ์ตœ๋Œ€ max()

 

# 2562 ์ตœ๋Œ“๊ฐ’

A = [int(input()) for _ in range (9)]

print(max(A))
print(A.index(max(A))+1)

- ๋ฆฌ์ŠคํŠธ A์— 9๊ฐœ ๊ฐ’ ๋„ฃ๊ธฐ

- A์—์„œ ์ตœ๋Œ“๊ฐ’์ด ๋ช‡ ๋ฒˆ์งธ ์ˆ˜์ธ์ง€ ์ถœ๋ ฅ : A.index(max(A))+1

 

# 10810 ๊ณต ๋„ฃ๊ธฐ

#i๋ฒˆ ๋ฐ”๊ตฌ๋‹ˆ๋ถ€ํ„ฐ j๋ฒˆ ๋ฐ”๊ตฌ๋‹ˆ๊นŒ์ง€ใ…” k๋ฒˆ ๋ฒˆํ˜ธ๊ฐ€ ์ ํ˜€์žˆ๋Š” ๊ณต์„ ๋„ฃ์Œ
#1๋ฒˆ๋ฐ”๊ตฌ๋‹ˆ๋ถ€ํ„ฐ N๋ฒˆ๋ฐ”๊ตฌ๋‹ˆ์— ๋“ค์–ด์žˆ๋Š” ๊ณต์˜ ๋ฒˆํ˜ธ๋ฅผ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•ด ์ถœ๋ ฅ

N, M = map(int, input().split()) #์ž…๋ ฅ๊ฐ’ ๊ณต๋ฐฑ ๊ธฐ์ค€์œผ๋กœ ๋ถ„๋ฆฌํ•˜์—ฌ ๊ฐ ๋ณ€์ˆ˜์— ๋„ฃ์Œ
A = [0]*N #0์œผ๋กœ ์ดˆ๊ธฐํ™”(์•ˆํ•˜๋ฉด ์˜ค๋ฅ˜๋œธ)

for _ in range (M) :
    i, j, k = map(int, input().split())
    for x in range(i, j+1, 1) :
        A[x-1] = k

for y in range (N) :
    print(A[y],end=' ')

- ๋ฐฐ์—ด ๋ฏธ๋ฆฌ 0์œผ๋กœ ์ดˆ๊ธฐํ™” ํ•ด์ค˜์•ผ ์˜ค๋ฅ˜ ์•ˆ ๋œธ

- ๋ณ€์ˆ˜ ์„ธ ๊ฐœ ํ•œ๋ฒˆ์— ์ž…๋ ฅ ๋ฐ›๊ธฐ : i, j, k = map(int, input().split())

 

# 10813 ๊ณต ๋ฐ”๊พธ๊ธฐ

#๋ฐ”๊ตฌ๋‹ˆ 1๋ฒˆ~N๋ฒˆ
#๋ฐ”๊ตฌ๋‹ˆ์— ๊ณต 1๊ฐœ์”ฉ, ์ฒ˜์Œ์—๋Š” ๋ฐ”๊ตฌ๋‹ˆ์— ์ ํ˜€์žˆ๋Š” ๋ฒˆํ˜ธ์™€ ๊ฐ™์€ ๋ฒˆํ˜ธ๊ฐ€ ์ ํžŒ ๊ณต ๋“ค์–ด์žˆ์Œ
#M๋ฒˆ ๊ณต ๋ฐ”๊พธ๊ธฐ
#๊ณต ๋ฐ”๊ฟ€ ๋ฐ”๊ตฌ๋‹ˆ 2๊ฐœ ์„ ํƒํ›„ ๋‘ ๋ฐ”๊ตฌ๋‹ˆ์— ๋“ค์–ด์žˆ๋Š” ๊ณต์„ ์„œ๋กœ ๊ตํ™˜

N, M = map(int,input().split())

A = [0]*N
for i in range(N) :
    A[i] = i+1

for _ in range (M) :
    i, j = map(int,input().split())
    tmp = A[i-1]
    A[i-1] = A[j-1]
    A[j-1] = tmp

for x in range (N) :
    print(A[x],end=' ')

- ๊ณต ๋ฐ”๊ฟ€ ๋•Œ tmp ๋ณ€์ˆ˜ ์‚ฌ์šฉ

 

# 5597 ๊ณผ์ œ ์•ˆ ๋‚ด์‹  ๋ถ„..?

A = [i for i in range(1,31)] #๋ฆฌ์ŠคํŠธ์— ๊ฐ’ ์ˆœ์„œ๋Œ€๋กœ ์ง‘์–ด๋„ฃ๊ธฐ

for _ in range(28) :
    B = int(input()) #์ž…๋ ฅ๊ฐ’
    A.remove(B) #์†Œ๊ฑฐ!! 

print(min(A))
print(max(A))

- ์ž…๋ ฅ๊ฐ’ ์ œ์™ธํ•œ ๊ฐ’ ์ฐพ๊ธฐ : remove์‚ฌ์šฉ

- A.remove(B) : ๋ฆฌ์ŠคํŠธ A์—์„œ B๊ฐ’ ์ œ์™ธํ•˜๊ธฐ

 

# 3052 ๋‚˜๋จธ์ง€

#์ˆ˜ 10๊ฐœ ์ž…๋ ฅ -> 42๋กœ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€
#์„œ๋กœ ๋‹ค๋ฅธ ๊ฐ’ ๋ช‡ ๊ฐœ?
A=[0]*10
for i in range(10) :
    x = int(input())
    A[i] = (x % 42)

B = set(A)
print(len(B))

- ๋ฆฌ์ŠคํŠธ ์ž…๋ ฅ ๋ฐ›๊ณ  ๋ฆฌ์ŠคํŠธ๋ฅผ ์ง‘ํ•ฉ์œผ๋กœ ๋ฐ”๊ฟ”์„œ ์ค‘๋ณต๋˜๋Š” ์ˆ˜ ์ œ๊ฑฐ

- len(B) = ์„œ๋กœ ๋‹ค๋ฅธ ์ˆ˜์˜ ๊ฐœ์ˆ˜

 

# 10811 ๋ฐ”๊ตฌ๋‹ˆ

#๋ฐ”๊ตฌ๋‹ˆ N๊ฐœ 1~N๋ฒˆ
#M๋ฒˆ ๋ฐ”๊ตฌ๋‹ˆ ์ˆœ์„œ๋ฅผ ์—ญ์ˆœ์œผ๋กœ
#์ˆœ์„œ๋ฅผ ์—ญ์ˆœ์œผ๋กœ ๋งŒ๋“ค ๋ฒ”์œ„ ์ •ํ•˜๊ณ  ๊ทธ ๋ฒ”์œ„์— ๋“ค์–ด์žˆ๋Š” ๋ฐ”๊ตฌ๋‹ˆ์˜ ์ˆœ์„œ๋ฅผ ์—ญ์ˆœ์œผ๋กœ
N, M = map(int,input().split())
A = [i+1 for i in range (N)]

for _ in range(M) :
    i, j = map(int,input().split())
    tmp = A[i-1:j] 
    tmp.reverse()
    A[i-1:j] = tmp

for i in range(N):
    print(A[i],end=' ')

- ์—ญ์ˆœ์œผ๋กœ ๋งŒ๋“ค๊ธฐ : tmp.reverse()

 

#1546 ํ‰๊ท 

#์ ์ˆ˜ ์ตœ๋Œ“๊ฐ’ M
#๋ชจ๋“  ์ ์ˆ˜๋ฅผ ์ ์ˆ˜/M*100

N = int(input()) #์‹œํ—˜ ๋ณธ ๊ณผ๋ชฉ ๊ฐœ์ˆ˜

A = list(map(int,input().split())) #์ ์ˆ˜
M = max(A)

B=[]
for i in A : #๋ฆฌ์ŠคํŠธ A ์•ˆ์˜ ์ˆ˜
    B.append(i/M*100) #์ƒˆ๋กœ์šด ์ ์ˆ˜ ์ƒ์„ฑ

res = sum(B)/N
print(res)

- for i in A : ๋ฆฌ์ŠคํŠธ A์•ˆ์˜ ์ˆ˜(i)