[BOJ] 2864 5와 6의 차이

[BOJ] 2864 5와 6의 차이

문제 링크

문자열을 대치하는 메서드가 있는지 모르고 굉장히 피로도 높게 풀이한 문제. replace함수를 쓰면 후딱 끝나는 문제다.

나의 풀이

import sys
input = sys.stdin.readline()
a, b = input.split(" ")

maxA = 0
maxB = 0
minA = 0
minB = 0

temp=""

for i in a:
  if (i == '5'):
    temp = temp + '6'
  else:
    temp = temp + i

maxA = int(temp)
temp=""

for i in a:
  if (i == '6'):
    temp = temp + '5'
  else:
    temp = temp + i

minA = int(temp)
temp=""

for i in b:
  if (i == '5'):
    temp = temp + '6'
  else:
    temp = temp + i

maxB = int(temp)
temp=""

for i in b:
  if (i == '6'):
    temp = temp + '5'
  else:
    temp = temp + i

minB = int(temp)

print(minA+minB, maxA+maxB)

다른 풀이

import sys

A, B = list(sys.stdin.readline().split())

worst =  int(A.replace("6","5")) + int(B.replace("6","5"))
best =  int(A.replace("5","6")) + int(B.replace( "5","6",))
print(worst, best)


© 2021. All rights reserved.