31797번 - 아~파트 아파트
n,m = map(int, input().split()) person = [""] * 20001 cnt = 0 for i in range(m): a, b = map(int, input().split()) person[a] = i + 1 person[b] = i + 1 for i in range(20001): if not person[i] == "": cnt += 1 if cnt == n: print(person[i])
어디 부분이 잘못되었을까요?
이런 경우에 출력이 없습니다.
https://ideone.com/AXeEef
이 코드는 20000층까지 반복 과정에서 cnt가 N이 되지 않으면 출력하지 않습니다.
댓글을 작성하려면 로그인해야 합니다.
morris7 2년 전
n,m = map(int, input().split()) person = [""] * 20001 cnt = 0 for i in range(m): a, b = map(int, input().split()) person[a] = i + 1 person[b] = i + 1 for i in range(20001): if not person[i] == "": cnt += 1 if cnt == n: print(person[i])
어디 부분이 잘못되었을까요?