BOJ/๐Ÿฅ‰

โ˜…Implementation Basics II - 24 Solvedโ˜…

metamong 2022. 8. 17.

โ˜… 5341 Pyramids โ˜…

 

while 1:
    N=int(input())
    if N==0:break
    s=0
    for i in range(1,N+1):s+=i
    print(s)

 


โ˜… 5300 Fill the Rowboats! โ˜…

 

N=int(input())
n=0
for i in range(1,N+1):
    print(i,end=' ')
    if i%6==0: print('Go!',end=' ')
if N%6!=0:print('Go!')

โ˜… 10188 Quadrilateral โ˜…

 

for _ in range(int(input())):
    a,b=map(int,input().split())
    for _ in range(b):
        print('X'*a)
    print()

โ˜… 10179 ์ฟ ํฐ โ˜…

 

for _ in range(int(input())):
    money=float(input())
    print(f'${money*0.8:.2f}')

โ˜… 9286 Gradabase โ˜…

 

for i in range(1,int(input())+1):
    n=int(input())
    m=list(int(input()) for _ in range(n))
    print(f'Case {i}:')
    for x in m:
        if x != 6:
            print(x+1)

โ˜… 10103 ์ฃผ์‚ฌ์œ„ ๊ฒŒ์ž„ โ˜…

 

a,b=100,100
for _ in range(int(input())):
    c,d=map(int,input().split())
    if c<d:a-=d
    elif d<c:b-=c
    else:pass
print(a,b,sep='\n')

 


โ˜… 5751 Head or Tail โ˜…

 

while 1:
    N=int(input())
    if N==0:break
    l=list(map(int,input().split()))
    a=l.count(0)
    b=l.count(1)
    print(f'Mary won {a} times and John won {b} times')

 

๐Ÿ‘ฉ‍๐ŸŽจ list์˜ count method๋ฅผ ํ†ตํ•ด 0์˜ ๊ฐœ์ˆ˜, 1์˜ ๊ฐœ์ˆ˜๋กœ ์‰ฝ๊ฒŒ ์ถœ๋ ฅ!


โ˜… 10813 ๊ณต ๋ฐ”๊พธ๊ธฐ โ˜…

 

import sys
input=sys.stdin.readline

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

basket = [i for i in range(1,N+1)]
for _ in range(M):
    i,j=map(int,input().split())
    basket[i-1],basket[j-1]=basket[j-1],basket[i-1]
print(*basket)

 

๐Ÿ‘ฉ‍๐ŸŽจ ํŒŒ์ด์ฌ swap์€ ,๋กœ ๋ฐ”๋กœ ๋‚˜์—ด


โ˜… 27918 ํƒ๊ตฌ ๊ฒฝ๊ธฐ โ˜…

 

d,p=0,0
flag=False
for _ in range(int(input())):
    res = input()

    if res == 'D':
        d+=1
    else:
        p+=1
    
    if abs(d-p) == 2:
        flag=True
        print(f'{d}:{p}')
        break
if not flag:
    print(f'{d}:{p}')

โ˜… 11654 ์•„์Šคํ‚ค ์ฝ”๋“œ โ˜…

 

print(ord(input()))

 

๐Ÿ’‚ ์ž…๋ ฅ์œผ๋กœ ์ฃผ์–ด์ง„ ๋ฌธ์ž์˜ ASCII ์ฝ”๋“œ ๋ฒˆํ˜ธ๋กœ ๋‚˜ํƒ€๋‚ด์ฃผ๋Š” ํ•จ์ˆ˜ ord() / ๋ฐ˜๋Œ€๋กœ ASCII ๋ฒˆํ˜ธ ์ฝ”๋“œ๋ฅผ ๋ฌธ์ž๋กœ ๋ณ€ํ™˜ํ•ด์ฃผ๋Š” ํ•จ์ˆ˜๋Š” chr()


โ˜… 1371 2์ง„์ˆ˜ 8์ง„์ˆ˜ โ˜…

 

๐Ÿ’‚ 2์ง„์ˆ˜๋ฅผ 8์ง„์ˆ˜๋กœ ํ•œ ๋ฒˆ์— ๋ณ€ํ™˜ํ•ด์ฃผ๋Š” oct()ํ•จ์ˆ˜๊ฐ€ ์žˆ๊ธด ํ•œ๋ฐ, ์ง์ ‘ 8์ง„์ˆ˜๋กœ์˜ ๋ณ€ํ™˜๋ฒ•์„ ์—ฐ๊ตฌํ•ด ํ’€์—ˆ๋‹ค. โ‘  2์ง„์ˆ˜๋ฅผ ๊ฑฐ๊พธ๋กœ ๋’ค์ง‘์Œ / โ‘ก 3๊ฐœ์”ฉ ๋ฌถ์Œ์œผ๋กœ ๋‚˜๋ˆ” - ๊ธธ์ด๊ฐ€ 3์œผ๋กœ ๋‚˜๋ˆ„์–ด์ง€์ง€ ์•Š์œผ๋ฉด, ๋์— 0 ๋˜๋Š” 00์„ ๋ถ™์—ฌ 3๊ฐœ์”ฉ ๋ฌถ์Œ์œผ๋กœ ์ •ํ™•ํžˆ ๋‚˜๋ˆ„๊ฒŒ / โ‘ข ๊ฐ ๋ฌถ์Œ๋ณ„๋กœ 1, 2, 4์”ฉ ๊ณฑํ•ด ๋”ํ•œ ๊ฒฐ๊ณผ - ์ฆ‰, ๊ฐ ๋ฌถ์Œ๋ณ„์˜ ๊ฒฐ๊ณผ๋ฅผ ๋‚˜์—ด / โ‘ฃ ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ๋’ค์ง‘์€ ๊ฒŒ 8์ง„์ˆ˜

๐Ÿ’‚  ์ œ์ถœํ˜„ํ™ฉ

 

โ‘  528ms ์‹คํ–‰

N = input()

two = list(reversed(N))
eight = []

two_length = len(two)

if two_length%3 == 1:
    two.extend(['0','0'])
    two_length += 2

elif len(two)%3 == 2:
    two.append('0')
    two_length += 1

for i in range(0, two_length-1, 3):
    eight.append(int(two[i])*1 + int(two[i+1])*2 + int(two[i+2])*4)

for i in reversed(eight):
    print(i, end="")

 

โ‘ก 448ms ์‹คํ–‰

N = input()

two = list(reversed(N))
eight = ''

if len(two)%3 == 1:
    two.extend(['0','0'])

elif len(two)%3 == 2:
    two.append('0')

for i in range(0, len(two)-1, 3):
    eight = eight + str(int(two[i])*1 + int(two[i+1])*2 + int(two[i+2])*4)

print(''.join(reversed(eight)))

 

โ‘ข 440ms ์‹คํ–‰

N = input()

two = list(reversed(N))
eight = ''

two_length = len(two)

if two_length%3 == 1:
    two.extend(['0','0'])
    two_length += 2

elif two_length%3 == 2:
    two.append('0')
    two_length += 1

for i in range(0, two_length-1, 3):
    eight = eight + str(int(two[i])*1 + int(two[i+1])*2 + int(two[i+2])*4)

print(''.join(reversed(eight)))

 

๐Ÿ’‚ ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•œ ํ’€์ด>

print(oct(int(input(),2))[2:])

→ input()์œผ๋กœ ๋ฐ›์€ 2์ง„์ˆ˜๋ฅผ int()๋กœ 10์ง„์ˆ˜๋กœ ๋ณ€ํ™˜ / 10์ง„์ˆ˜๋กœ ๋ณ€ํ™˜๋œ int()์˜ ๊ฒฐ๊ณผ๋ฅผ oct()๋กœ 8์ง„์ˆ˜๋กœ ๋ณ€ํ™˜ (oct()๋Š” 10์ง„์ˆ˜๋ฅผ 8์ง„์ˆ˜๋กœ ๋ณ€ํ™˜ํ•ด์คŒ) / ๋งจ ์•ž์— 0c๊ฐ€ ๋ถ™์–ด์žˆ์œผ๋ฏ€๋กœ ์•ž์— ๋‘ ์ž๋ฆฌ๋งŒ ๋–ผ์ฃผ๊ณ  ๊ฒฐ๊ณผ ์ถœ๋ ฅ!


โ˜… 10699 ์˜ค๋Š˜ ๋‚ ์งœ โ˜…

 

๐Ÿ’‚ datetime library๋ฅผ ์ด์šฉํ•ด ํ˜„์žฌ ๋‚ ์งœ, ์‹œ๊ฐ์„ ์ •ํ™•ํžˆ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค

from datetime import datetime

print(datetime.today().strftime("%Y-%m-%d"))

 

๐Ÿ’‚ datetime์˜ today() ํ•จ์ˆ˜๋กœ ์˜ค๋Š˜์„ ๊ฐ€์ ธ์˜ค๊ณ , today() ํ•จ์ˆ˜์˜ strftime() method๋ฅผ ํ†ตํ•ด ๋…„,์›”,์ผ๋งŒ ๋‚˜ํƒ€๋‚ด๊ณ , ์‚ฌ์ด์— - ๋ฅผ ๋ถ™์—ฌ ๋‚˜ํƒ€๋‚ด๋Š” ํ˜•์‹์„ ์ •ํ•ด์ค€๋‹ค.


โ˜… 16170 ์˜ค๋Š˜์˜ ๋‚ ์งœ๋Š”? โ˜…

 

from datetime import datetime

date = str(datetime.utcnow()).split(' ')[0].split('-')
print(date[0], date[1], date[2], sep='\n')

 

๐Ÿ’‚ KST ๊ธฐ์ค€์ด ์•„๋‹Œ,UTC +0 ๊ธฐ์ค€์ด๋ฏ€๋กœ, googlingํ•œ ๊ฒฐ๊ณผ datetime ๋ชจ๋“ˆ์˜ utcnow()๋ผ๋Š” ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด์„œ ๋‹ต์„ ๊ตฌํ•  ์ˆ˜ ์žˆ์Œ์„ ์•Œ์•˜์Œ! ๋‹ค๋งŒ, utcnow()๋Š” ์ดˆ๊นŒ์ง€ ๋ชจ๋“  ์‹œ๊ฐ์„ ์ •ํ™•ํžˆ ๋ฆฌํ„ดํ•˜๋ฏ€๋กœ, datetime type์„ string ๋ฌธ์ž์—ด๋กœ ๋ฐ”๊ฟ”์ค€๋‹ค์Œ, split()๊ณผ indexing์„ ํ†ตํ•ด ์›ํ•˜๋Š” ๊ฒฐ๊ณผ๋งŒ ์ถœ๋ ฅํ•˜๊ฒŒ codingํ•จ


โ˜… 3052 ๋‚˜๋จธ์ง€ โ˜…

 

lst = []

for _ in range(10):
    N = int(input())
    lst.append(N%42)

print(len(set(lst)))

 

๐Ÿ’‚ ์„œ๋กœ ๋‹ค๋ฅธ ๊ฐ’์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ๊ฒƒ์ด๋ฏ€๋กœ set() ํ•จ์ˆ˜๋ฅผ ํ™œ์šฉํ•ด์„œ ์ค‘๋ณต์„ ์ œ์™ธํ•œ ๊ฐ’์„ ์นด์šดํŠธํ•˜๋ฉด ๋œ๋‹ค. ๋”ฐ๋ผ์„œ ์œ„ ๋ฌธ์ œ์˜ ๊ฒฝ์šฐ 42๋กœ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€์˜ ์ข…๋ฅ˜ ๊ฐœ์ˆ˜๋งŒ ๊ตฌํ•˜๊ฒŒ ํ•˜๋ ค๋ฉด set() ํ™œ์šฉํ•˜๋ฉด ๋ฐ”๋กœ ๊ตฌํ•  ์ˆ˜ ์žˆ์Œ (๋˜๋Š” not in ์—ฐ์‚ฐ์ž๋ฅผ ํ™œ์šฉํ•ด์„œ๋„ ํ’€ ์ˆ˜ ์žˆ์Œ)


โ˜… 14623 ๊ฐ์ •์ด์ž… โ˜…

 

B1 = int(input(),2)
B2 = int(input(),2)

print(bin(B1*B2)[2:])

 

๐Ÿ’‚ 2์ง„์ˆ˜ ๊ด€๋ จ ์•„๋ž˜ ์ด ๋‘ ๊ฐ€์ง€

 

โ‘  bin() ํ•จ์ˆ˜

 

→ bin()์•ˆ์— ๋“ค์–ด๊ฐ„ 10์ง„์ˆ˜ ์ˆซ์ž๋ฅผ ์ด์ง„์ˆ˜๋กœ ๋ฐ”๊ฟ”์ค€๋‹ค. ์ด๋•Œ 0b๊ฐ€ ๊ฐ™์ด ์ถœ๋ ฅ๋˜๋ฏ€๋กœ slicing๊ธฐ๋ฒ•์„ ์ด์šฉํ•˜๊ฑฐ๋‚˜ .format()์˜ 'b' ๋˜๋Š” f-string์˜ {:b}๋ฅผ ์ด์šฉํ•˜๋ฉด 0b์—†์ด ์ˆœ์ˆ˜ 2์ง„์ˆ˜๋งŒ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Œ

 

โ‘ก ์ง„์ˆ˜์˜ ๋ฌธ์ž์—ด์„ ์ˆซ์ž๋กœ ๋ณ€ํ™” → int(,x)๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ฒซ ๋ฒˆ์งธ ์ธ์ž๋กœ ๋“ค์–ด์˜จ ์ˆ˜๋ฅผ x์ง„๋ฒ•์œผ๋กœ ํ•ด์„ํ•ด ์‹ญ์ง„์ˆ˜๋กœ ํ‘œํ˜„


โ˜… 5893 17๋ฐฐ โ˜…

 

N=int(input(),2)
print(bin(N*17)[2:])

โ˜… 1924 2007๋…„ โ˜…

 

x, y = map(int, input().split())

days = 0

for i in range(1,x):
    if i in [1,3,5,7,8,10,12]:
        days += 31

    elif i in [4,6,9,11]:
        days += 30
    
    else:
        days += 28

days += y

day = {1: 'MON', 2: 'TUE', 3: 'WED', 4: 'THU', 5: 'FRI', 6: 'SAT', 0: 'SUN'}

print(day[days%7])

 

๐Ÿค™ ์‹œ๊ณ„ ๋ฌธ์ œํ’€์ดํ•˜๊ณ  ๋น„์Šทํ•˜๊ฒŒ 2007๋…„ 1์›” 1์ผ๋ถ€ํ„ฐ ์ง€์ •์ผ๊นŒ์ง€ ๋ชจ๋“  ์ผ ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•œ๋’ค, 7์„ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€์— ๋”ฐ๋ผ ์š”์ผ์„ ๋ถ€์—ฌํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์š”์ผ์„ ์‰ฝ๊ฒŒ ๊ณ„์‚ฐํ•  ์ˆ˜ ์žˆ๋‹ค.

๐Ÿ’‚ calender module ๐Ÿ’‚

import calender
arrList = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"]
x, y = map(int,input().split())

Day = calendar.weekday(2007, x, y)
print(arrList[Day])

 

๐Ÿค™ ์•„๋ž˜ weekday()ํ•จ์ˆ˜๋Š” 1970๋…„ 1์›” 1์ผ๋ถ€ํ„ฐ ์›ํ•˜๋Š” ๋‚ ์งœ๋ฅผ ๋„ฃ์œผ๋ฉด ์š”์ผ์˜ ์ˆซ์ž๋ฅผ ๋ฐ˜ํ™˜ํ•ด์ค€๋‹ค. (์›”์š”์ผ 0๋ถ€ํ„ฐ ์‹œ์ž‘)


โ˜… 11283 ํ•œ๊ธ€ 2 โ˜…

 

print(ord(input())-ord('๊ฐ€')+1)

 

๐Ÿค™ ord() ํ•จ์ˆ˜๊ฐ€ ํ•œ๊ธ€๋„ ์œ„ ๋ฌธ์ œ์—์„œ ์–ธ๊ธ‰๋˜์—ˆ๋“ฏ์ด ๊ฐ€ - ๊ฐ - ๊ฐ‚ - ~ ์ˆœ์„œ๋Œ€๋กœ ์ˆซ์ž๋ฅผ ๋งค๊ฒจ, ํ•ด๋‹น ํ•œ๊ธ€ ๋ณ„ ์ˆซ์ž๋ฅผ ๋ฐ˜ํ™˜


โ˜… 11282 ํ•œ๊ธ€ โ˜…

 

print(chr(44031+int(input())))

 

๐Ÿค™ ์œ„ ord() ํ•จ์ˆ˜์˜ ๋ฐ˜๋Œ€๋Š” chr(), ์—ฌ๊ธฐ์„œ '๊ฐ€'๋Š” ์ˆซ์ž๋กœ 44032์ด๋ฏ€๋กœ 44031๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด 1๋ถ€ํ„ฐ ์ฐจ๋ก€๋กœ ๋”ํ•œ ๊ฒฐ๊ณผ๊ฐ€ ์ถœ๋ ฅ๋œ๋‹ค


โ˜… 26500 Absolutely โ˜…

 

for _ in range(int(input())):
    a,b=map(float,input().split())
    print(round(abs(a-b),1))

 

๐Ÿค™ ๋‘ ์  ์‚ฌ์ด์˜ ๊ฑฐ๋ฆฌ๋ฅผ ์†Œ์ˆ˜ ์ฒซ์งธ์ž๋ฆฌ๊นŒ์ง€๋งŒ ๋ฐ˜์˜ฌ๋ฆผํ•ด์„œ ๋‚˜ํƒ€๋‚ด๋Š” ๋ฐฉ๋ฒ•์€ round()ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉ!


โ˜… 5356 Triangles โ˜…

 

for _ in range(int(input())):
    a,b=input().split()
    start=ord(b)
    for i in range(int(a)):
        print(chr(start)*(i+1))       
        if start !=90:start+=1
        else:start=65
    print()

 

๐Ÿค™ ord()์™€ chr() ๋‘ ์•„์Šคํ‚ค ์ฝ”๋“œ ํ•จ์ˆ˜๋กœ ๊ตฌํ˜„! A๋Š” 65๋ฒˆ, Z๋Š” 90๋ฒˆ์ž„์„ ๊ณ ๋ คํ•ด Z์ผ ๊ฒฝ์šฐ A๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋„๋ก ์„ค์ •


โ˜… 5220 Error Detection โ˜…

 

for _ in range(int(input())):
    value,check_bit=map(int,input().split())
    n=bin(value)[2:].count('1')
    if n%2==1:
        if check_bit==1: print('Valid')
        else: print('Corrupt')
    else:
        if check_bit==0: print('Valid')
        else: print('Corrupt')

 

๐Ÿค™ bin() ํ•จ์ˆ˜๋กœ 0๊ณผ 1๋กœ ๊ตฌ์„ฑ๋œ ์ด์ง„์ˆ˜๋กœ ๋ณ€ํ™˜ํ•ด check_bit ์ผ์น˜ ์—ฌ๋ถ€ ํŒ๋‹จ!


โ˜… 3460 ์ด์ง„์ˆ˜ โ˜…

 

for _ in range(int(input())):

    n=int(input())
    ans=[]
    i=0
    for x in bin(n)[2:][::-1]:
        if x=='1':
            ans.append(i)
        i+=1
    print(*ans)

 

๐Ÿค™ ์—ญ์‹œ bin() ํ•จ์ˆ˜ ์‚ฌ์šฉ


โ˜… 3059 ๋“ฑ์žฅํ•˜์ง€ ์•Š๋Š” ๋ฌธ์ž์˜ ํ•ฉ โ˜…

 

import sys
input=sys.stdin.readline

alphabets='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for _ in range(int(input())):
    S=input()
    ans=0
    for ch in alphabets:
        if ch not in S:
            ans+=ord(ch)
    print(ans)

 

๐Ÿค™ ์ฃผ์–ด์ง„ ๋ฌธ์ž์˜ ASCII ์ฝ”๋“œ ์ˆซ์ž๋กœ ๋ณ€ํ™˜ํ•ด์ฃผ๋Š” ord() ํ•จ์ˆ˜ ์‚ฌ์šฉ!


 

 

 

 

 

 

 

 

 

'BOJ > ๐Ÿฅ‰' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

โ˜…Implementation Beginner I - 50 Solvedโ˜…  (0) 2022.08.22
โ˜…Number Theory Upper-Beginner I - 15 Solvedโ˜…  (0) 2022.08.21
โ˜…Math Beginner I - 30 Solvedโ˜…  (0) 2022.08.16
โ˜…Implementation Basics I - 50 Solvedโ˜…  (0) 2022.08.04
โ˜…Basics I - 50 Solvedโ˜…  (0) 2022.07.31

๋Œ“๊ธ€