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

[๋ฐฑ์ค€ ํŒŒ์ด์ฌ] ๋‹จ๊ณ„๋ณ„๋กœ ํ’€์–ด๋ณด๊ธฐ - Lv3.๋ฐ˜๋ณต๋ฌธ

HHRR 2023. 4. 11. 05:28

# 25304 ์˜์ˆ˜์ฆ

#X : ์˜์ˆ˜์ฆ ์ด๊ธˆ์•ก
#N : ์˜์ˆ˜์ฆ ๊ตฌ๋งค ๋ฌผ๊ฑด์˜ ์ข…๋ฅ˜ ์ˆ˜
#๊ฐ€๊ฒฉ a, ๊ฐœ์ˆ˜ b

X=int(input())
N=int(input())
sum=0

for i in range (N) :
    a,b = map(int,input().split())
    sum += a*b

if sum==X :
    print("Yes")
else :
    print("No")

- sum=0 ์œผ๋กœ ๋ฏธ๋ฆฌ ์ดˆ๊ธฐํ™”ํ•ด์ฃผ๊ธฐ

 

# 25314 ์ฝ”๋”ฉ์€ ์ฒด์œก๊ณผ๋ชฉ ์ž…๋‹ˆ๋‹ค.

N=int(input())
x = int(N/4)

for i in range(x) :
    print("long", end=' ')
print("int")

- end= ' ' : ๋ถ™์—ฌ์„œ ์ถœ๋ ฅํ•ด์คŒ, ๊ตฌ๋ถ„์€ ๊ณต๋ฐฑ

 

# 15552 ๋น ๋ฅธ A+B

import sys

T=int(input())

for i in range(T) :
    a,b=map(int,sys.stdin.readline().split())
    print(a+b)

- ๋ฐ˜๋ณต๋ฌธ์—์„œ ์ž…๋ ฅ ๋น ๋ฅด๊ฒŒ ํ•˜๊ธฐ : sys.stdin.readline() ์‚ฌ์šฉ

- sys import ํ•ด์ค˜์•ผํ•จ

 

# 11021 A+B -7

import sys

T=int(input())

for i in range(T) :
    a,b=map(int,sys.stdin.readline().split())
    print(f'Case #{i+1}: {a+b}')
#f-string : {}์•ˆ์˜ ์ˆ˜ ๋ณ€์ˆ˜ ์ถœ๋ ฅ

- Case #{1} : {5}

- f-string : {}์•ˆ์˜ ์ˆ˜๋Š” ๋ณ€์ˆ˜ ์ถœ๋ ฅ, ์ด์™ธ์˜ ๋ฌธ์ž์—ด ๊ณ ์ • ์ถœ๋ ฅ

  f'๋ฌธ์ž์—ด{๋ณ€์ˆ˜}'

 

# 11022 A+B -8

import sys

T=int(input())

for i in range(T) :
    a,b=map(int,sys.stdin.readline().split())
    print(f'Case #{i+1}: {a} + {b} = {a+b}')

# 2438 ๋ณ„์ฐ๊ธฐ-1

N=int(input())

for i in range(1,N+1) :
    print("*"*(i))

- "๋ฌธ์ž"*(๊ฐœ์ˆ˜) : ๋‚ด๊ฐ€ ์›ํ•˜๋Š” ๊ฐœ์ˆ˜๋งŒํผ ๋ฌธ์ž ์ถœ๋ ฅ

 

# 2439 ๋ณ„์ฐ๊ธฐ-2

N=int(input())

for i in range(1,N+1) :
    print(" "*(N-i) + "*"*i)

 

# 10952 A+B -5

while(1) :
    a,b = map(int,input().split())
    if (a==0 & b==0) :
        break
    print(a+b)

 

# 10951 A+B -4

while(1) :
    try:
        a,b = map(int,input().split())
        print(a+b)
    except :
        break

- try except ์‚ฌ์šฉ : try ์ด์™ธ์˜ ๊ฒฝ์šฐ except ์‹คํ–‰