오늘 정처기 필기 합격 결과가 나와서 보니까 예상했다싶이 합격!!
얼른 응시자격서류 제출하고 (무슨 3000원씩이나 드냐;;)
오늘치 문제를 풀었다.
Identify, Sort, Index, Solve_26150
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
class Problem {
String s;
int i;
int d;
Problem(String s, int i, int d) {
this.s = s;
this.i = i;
this.d = d;
}
public int getI() {
return i;
}
}
public class IdentifySortIndexSolve_26150 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
Problem[] prob = new Problem[n];
for (int a = 0; a < n; a++) {
StringTokenizer st = new StringTokenizer(br.readLine());
String s = st.nextToken();
int i = Integer.parseInt(st.nextToken());
int d = Integer.parseInt(st.nextToken());
prob[a] = new Problem(s, i, d);
}
Arrays.sort(prob, new Comparator<Problem>() {
@Override
public int compare(Problem p1, Problem p2) {
return Integer.compare(p1.i, p2.i);
}
});
String result = "";
for (int a = 0; a < n; a++) {
int num = prob[a].d;
String word = prob[a].s;
result += word.charAt(num - 1);
}
bw.write(result.toUpperCase());
bw.flush();
bw.close();
}
}
변수 3개에 특정 변수 기준 정렬이 필요한 문제라 초반엔 Comparable을 implements 해서 풀어야 하나 했는데, 검색해보니까 매번 정렬마다 저렇게 조건을 설정하는 법도 있어서 써봤다. 저게 더 편한 듯?
그리고 charAt()은 0-based가 아니고 1-based 더라... ㅋㅋ 왜 NullPointerException이 뜨나 했네.
마지막으로 toUpperCase()나 toLowerCase()는 숫자 상관없이 빈거 다 대문자로 만들어주는 사기 기능이었다!! 애용해야지.