코딩테스트/백준
[백준 1205번] 등수 구하기
seung_ho_choi.s
2025. 1. 24. 18:35
728x90
https://www.acmicpc.net/problem/1205
# frozen_string_literal: true
N, S, P = gets.chomp.split.map(&:to_i)
score = []
if N != 0
score = gets.chomp.split.map(&:to_i)
end
if P != 0
index_of = 1
else
index_of = 0
end
cnt = 0
if score.index(S).nil?
for i in 0...N
cnt += 1
if S > score[i]
index_of = cnt
break
end
if i == N - 1
if cnt + 1 <= P
index_of = cnt +1
else
index_of = -1
end
end
end
else
index_of = score.index(S) + 1
end
if S == score[N - 1] && index_of >= P
index_of = -1
elsif S == score[N - 1] && N == P
index_of = -1
end
puts index_of
정말 짜증이 났던 문제였다. 😤 실버 4 치고는 요구 조건이 너무 많아서, 체감상 실버 1 정도는 되는 것 같다.
문제 자체는 크게 어렵지 않았지만, 까다로운 조건들이 많아서 시간이 걸렸다. 특히, 루비로 풀어서 더 힘들었던 것 같다.
이런 문제를 만나면 정말 고생이지만, 그래도 풀고 나니 뿌듯함은 있다.
728x90