๐Ÿง ๋ฐฑ์ค€ 1427, 1676, 2577, 2711  _ ๋‹จ์ผ ์ˆซ์ž์— ๋Œ€ํ•œ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ด์šฉํ•œ ์ ‘๊ทผ

๐Ÿคซ ํ•ด๊ฒฐ์˜ ์‹ค๋งˆ๋ฆฌ 

๐Ÿค” ๋‹จ์ผ์ˆซ์ž๋‚˜ ๋ฌธ์ž์—ด์— ๋Œ€ํ•œ ์ ‘๊ทผ์ด๋‚˜ ๋ฆฌ์ŠคํŠธ๋กœ ์–ด๋–ป๊ฒŒ ๋ฐ”๊ฟ€๊นŒ?

๐Ÿ™ƒ ๋‹จ์ผ ์ˆซ์ž์˜ ๊ฒฝ์šฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.
1. ๋‹จ์ผ ์ˆซ์ž๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋ฐ”๊พผ๋‹ค.
2. ๋ฌธ์ž์—ด์„ ๋ฆฌ์ŠคํŠธ์— ๋„ฃ๋Š”๋‹ค.
str_num = str(n)
str_list = list(str_num)โ€‹

๐Ÿ™ƒ ๋ฌธ์ œ์— ๋งž๋Š” ์—ฐ์‚ฐ ์ง„ํ–‰ ํ›„ ๋‹ค์‹œ ์ˆซ์ž๋กœ ์ถœ๋ ฅํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด?
3. ๋ฆฌ์ŠคํŠธ๊ฐ’๋“ค์„ ์ถœ๋ ฅ
print(*sorted(num, reverse = True) , sep = '')
# sep=''๋ฅผ ํ†ตํ•ด ์›์†Œ๊ฐ„์˜ ๊ตฌ๋ถ„์ž์ธ ๊ณต๋ฐฑ์„ ์—†์• ์คŒ์œผ๋กœ
# 9 9 9 9 9 9 9 9 8 ์„
# 999999998 ๋กœ ์ถœ๋ ฅโ€‹


๐Ÿง ์‚ฌ์šฉ๋ฒ•์— ๋Œ€ํ•œ ์ •๋ฆฌ.

num = int(input())
str_x = list(str(num))          # ['1', '2', '3', '4', '5', '6']
int_x = list(map(int, str_x))   # [1, 2, 3, 4, 5, 6]

print(*int_x)           # 1 2 3 4 5 6
print(*int_x, sep="")   # 123456


 
๐Ÿค”  ์›ํ•˜๋Š” ์›์†Œ๋ฅผ ์–ด๋–ป๊ฒŒ ์ง€์šธ๊นŒ?  pop, del, remove ํ•จ์ˆ˜! 
# cf-1  pop
a = [1,2,1,3,4,5,1]
removed = a.pop(1)  # 1๋ฒˆ์งธ index ์‚ญ์ œ ๋‹จ, return ๊ฐ€๋Šฅ

print(a)            # [1, 1, 3, 4, 5, 1]
print(removed)      # 2   <-- popํ•œ ์›์†Œ๋ฅผ return ๊ฐ€๋Šฅ
# cf-2  del  -> pop๊ณผ ๋‹ค๋ฅด๊ฒŒ ๋ฆฌ์ŠคํŠธ์˜ ๋ฒ”์œ„๋ฅผ ์ง€์ •ํ•ด ์‚ญ์ œ ๊ฐ€๋Šฅ
a = [1,2,1,3,4,5,1]

del a[:2]
print(a)        # [1, 3, 4, 5, 1]
#cf-3   remove  -> ์œ„์™€ ๋‹ฌ๋ฆฌ ์ง€์šฐ๊ณ ์ž ํ•˜๋Š” ์ธ๋ฑ์Šค๊ฐ€ ์•„๋‹Œ ๊ฐ’์„ ์ž…๋ ฅ
for _ in numbers :
    numbers.remove(3)




๐Ÿคซ  solution_1427

# ์ž…๋ ฅ: 999998999

num = list(map(int, input()))  # ๊ณต๋ฐฑ์—†์ด ์ž…๋ ฅ๋ฐ›์„ ๋•Œ, list์— ์ €์žฅํ•˜๋Š” ๋ฒ•
print(*sorted(num, reverse = True) , sep = '')
# sep=''๋ฅผ ํ†ตํ•ด ์›์†Œ๊ฐ„์˜ ๊ตฌ๋ถ„์ž์ธ ๊ณต๋ฐฑ์„ ์—†์• ์คŒ์œผ๋กœ
# 9 9 9 9 9 9 9 9 8 ์„
# 999999998 ๋กœ ์ถœ๋ ฅ

# cf. end์˜ต์…˜์„ ์‚ฌ์šฉํ•˜๋ฉด ๊ทธ ๋’ค์— ๋‚˜์˜ค๋Š” ์ถœ๋ ฅ๊ฐ’๊ณผ ๊ตฌ๋ถ„์„ ์ง“๋Š” ๊ตฌ๋ถ„์ž ์—ญํ• ์„ ํ•œ๋‹ค.
print(*sorted(num, reverse = True) , end = " hello ")
print(num)
# 9 9 9 9 9 9 9 9 8 hello [9, 9, 9, 9, 9, 8, 9, 9, 9] ๊ฐ€ ์ถœ๋ ฅ


๐Ÿคซ  solution_1676

def fac(n):
    if n <= 1:
        return 1
    else:
        return n * fac(n - 1)

N = int(input())
n = fac(N)

# ์ˆซ์ž๋ฅผ ๋ฆฌ์ŠคํŠธ์— ํ•œ์ž๋ฆฌ์”ฉ ๋„ฃ๊ธฐ (์ˆซ์ž->๋ฌธ์ž์—ด)
str_num = str(n)
str_list = list(str_num)

cnt = 0
for i in reversed(str_list):
    if i == '0':
        cnt += 1
    else:
        break
print(cnt)

 

๐Ÿคซ  solution_2577

num = []
for i in range(3):
    n = int(input())
    num.append(n)

mul = 1
for i in range(3):
    mul *= num[i]

str_x = list(str(mul))
int_x = list(map(int, str_x))

out_ls = []
for i in range(10):
    out_ls.append(int_x.count(i))

for i in range(10):
    print(out_ls[i])

 

 

๐Ÿง ๋ฐฑ์ค€ 1292 , 4458 ํ’€์ด ๋ฐ ์‚ฌ์šฉํ•จ์ˆ˜

๐Ÿคซ ํ•ด๊ฒฐ์˜ ์‹ค๋งˆ๋ฆฌ 

๐Ÿค” ๋ฆฌ์ŠคํŠธ ์‚ฌ์šฉ์˜ ํ•ต์‹ฌ! ์ธ๋ฑ์Šค ์Šฌ๋ผ์ด์‹ฑ 
์ธ๋ฑ์Šค ์Šฌ๋ผ์ด์‹ฑ์— ๋Œ€ํ•œ ์‘์šฉ๋ฐฉ๋ฒ•์„ ์•„๋ž˜ ํ•ด์„ค์„ ํ†ตํ•ด ๋ณผ ์ˆ˜ ์žˆ๋Š”๋ฐ, [:]๋ฅผ ์ด์šฉํ•œ๋‹ค.



๐Ÿคซ  solution_1292

A, B = map(int, input().split())
num_sequences = []

for i in range(1000):
    for j in range(i):
        num_sequences.append(i
print(sum(num_sequences[A-1:B]))


๐Ÿคซ  solution_4458

for i in [input() for _ in range(int(input()))]:
    print(i[:1].upper() + i[1:])

 

 

 

๐Ÿง ๋ฐฑ์ค€ 1157  ํ’€์ด ๋ฐ ์‚ฌ์šฉ ํ•จ์ˆ˜

๐Ÿคซ ํ•ด๊ฒฐ์˜ ์‹ค๋งˆ๋ฆฌ 

๐Ÿค” ์›์†Œ๊ฐ€ ๊ฒน์น˜์ง€ ์•Š์•„? set ์ž๋ฃŒ๊ตฌ์กฐ 
์ฃผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๋ฆฌ์ŠคํŠธ๋กœ set์„ ๋ณ€ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.
a_set = set(a)
lst = []
for i in a_set:
    lst.append(a.count(i))


๐Ÿคซ  solution_1546

a = list(str(input()).upper())
a_set = set(a)
cnt = []
for i in a_set:
    cnt.append(a.count(i))
if cnt.count(max(cnt)) <= 1:
    print(max(a, key = a.count))
else:
    print("?")

 

๐Ÿง ๋ฐฑ์ค€ 1292 , 4458 ํ’€์ด ๋ฐ ์‚ฌ์šฉํ•จ์ˆ˜

๐Ÿคซ ํ•ด๊ฒฐ์˜ ์‹ค๋งˆ๋ฆฌ 

๐Ÿค” ๋ฆฌ์ŠคํŠธ ์‚ฌ์šฉ์˜ ํ•ต์‹ฌ! ์ธ๋ฑ์Šค ์Šฌ๋ผ์ด์‹ฑ 
์ธ๋ฑ์Šค ์Šฌ๋ผ์ด์‹ฑ์— ๋Œ€ํ•œ ์‘์šฉ๋ฐฉ๋ฒ•์„ ์•„๋ž˜ ํ•ด์„ค์„ ํ†ตํ•ด ๋ณผ ์ˆ˜ ์žˆ๋Š”๋ฐ, [:]๋ฅผ ์ด์šฉํ•œ๋‹ค.



๐Ÿคซ  solution_1292

A, B = map(int, input().split())
num_sequences = []

for i in range(1000):
    for j in range(i):
        num_sequences.append(i
print(sum(num_sequences[A-1:B]))


๐Ÿคซ  solution_4458

for i in [input() for _ in range(int(input()))]:
    print(i[:1].upper() + i[1:])

 

๐Ÿง ๋ฐฑ์ค€ 2309,  2822 ํ’€์ด ๋ฐ ์‚ฌ์šฉํ•จ์ˆ˜

๐Ÿคซ ํ•ด๊ฒฐ์˜ ์‹ค๋งˆ๋ฆฌ 

๐Ÿค” ์ •๋ ฌ์„ ์Šค์Šค๋กœ ํ•ด์ฃผ๋Š” ๋‚ด์žฅํ•จ์ˆ˜, sorted๋ฅผ ์ด์šฉํ•˜์ž! 

์ •๋ ฌ ํ•จ์ˆ˜๋Š” ๋‹ค์Œ 2๊ฐ€์ง€๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

a.sort()
sorted(a)

๋‘˜์˜ ์ฐจ์ด๋Š” ๋ฐ”๋กœ ๋ฐ˜ํ™˜์˜ ์—ฌ๋ถ€์ด๋‹ค.
a.sort์˜ ๊ฒฝ์šฐ, ๋ฐ˜ํ™˜์„ ํ•ด์ฃผ์ง€ ์•Š๊ธฐ์— print๋ฌธ์— ๋„ฃ์–ด์ฃผ๋ฉด ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๊ฒŒ ๋œ๋‹ค.
ํ•˜์ง€๋งŒ sorted์˜ ๊ฒฝ์šฐ, ๊ฐ’์˜ ๋ฐ˜ํ™˜์ด ์ด๋ฃจ์–ด์งˆ ์ˆ˜ ์žˆ์–ด์„œ print๋ฌธ์—์„œ๋„ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š”๋‹ค.


๐Ÿค” cf. ์ถœ๋ ฅ ์กฐ๊ฑด์— ๋”ฐ๋ผ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž‘์„ฑํ•˜์ž!
sorted(idx_list)  => [3, 4, 5, 6, 8]
*sorted(idx_list) =>   3 4 5 6 8


๐Ÿคซ  solution_2309

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

for i in range(len(dwarf)):
    for j in range(i+1, len(dwarf)):
        if (sum(dwarf) - (dwarf[i] + dwarf[j])) == 100:
            dwarf1, dwarf2 = dwarf[j], dwarf[i]  # out of index range ์กฐ์‹ฌ
            dwarf.remove(dwarf1)
            dwarf.remove(dwarf2)
            break
        else:
            continue

print(*sorted(dwarf), sep = "\n")

 

๐Ÿคซ  solution_2822

score = [int(input()) for _ in range(8)]
total = list(sorted(score, reverse=True))
print(sum(total[:5]))

idx_list = []
for i in range(5):
    idx_list.append(score.index(max(score)) + 1)
    score[score.index(max(score))] = -100
print(*sorted(idx_list))
# sorted(idx_list)  => [3, 4, 5, 6, 8]
# *sorted(idx_list) =>   3 4 5 6 8

 

 

๐Ÿง ๋ฐฑ์ค€ 11047 ํ’€์ด

๐Ÿคซ  solution_11047  (Greedy Algorithm)

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

coin = sorted([int(input()) for _ in range(N)], reverse=True)

cnt = 0
while K != 0:
    for i in range(N):
        if coin[i] > K:
            i -= 1
        else:
            frequency = K // coin[i]
            K -= coin[i] * frequency
            cnt += frequency
print(cnt)

 

+ Recent posts