www.acmicpc.net/step/2

 

 

 

 

1.  A + B -5 ( #10952번)

import sys
input = sys.stdin.readline

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

 

 


 

 

 

2. A + B -4 ( #10951번)

 

요는 exception.

예외 처리를 사용해 문제를 풀어야 함.

 

 

import sys
input = sys.stdin.readline

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

 

 

 

사용자가 try 부분에서 입력을 잘못해

(숫자 한번만 입력하거나 3번이상 입력,

str 입력등등) 에러가 발생할 경우,

프로그램 종료.

 

 

 


 

 

3. 더하기 사이클 ( #1110번)

import sys
input = sys.stdin.readline

n = num = int(input())
count = 0

while True:
    f_num = n // 10
    s_num = n % 10
    total = f_num + s_num
    n = int(str(n % 10) + str(total % 10))
    count += 1
    
    if num == n :
        break
        
print(count)

 

728x90
반응형

+ Recent posts