๋ฐ์ํ
๋ฌธ์ ๋ถ์
์๋ฅผ ๋ค์ด ์ด๋ค A, B ๋ ์ฌ๋์ ๋ฉ์น๊ฐ ๊ฐ๊ฐ (56, 177), (45, 165) ๋ผ๊ณ ํ๋ค๋ฉด A์ ๋ฉ์น๊ฐ B๋ณด๋ค ํฐ ์ ์ด ๋๋ค.
๊ทธ๋ฐ๋ฐ ์๋ก ๋ค๋ฅธ ๋ฉ์น๋ผ๋ฆฌ ํฌ๊ธฐ๋ฅผ ์ ํ ์ ์๋ ๊ฒฝ์ฐ๋ ์๋ค.
์๋ฅผ ๋ค์ด ๋ ์ฌ๋ C์ D์ ๋ฉ์น๊ฐ ๊ฐ๊ฐ (45, 181), (55,173)์ด๋ผ๋ฉด ๋ชธ๋ฌด๊ฒ๋ D๊ฐ C๋ณด๋ค ๋ ๋ฌด๊ฒ๊ณ , ํค๋ C๊ฐ ๋ ํฌ๋ฏ๋ก, "๋ฉ์น"๋ก๋ง ๋ณผ ๋ C์ D๋ ๋๊ตฌ๋ ์๋๋ฐฉ๋ณด๋ค ๋ ํฌ๋ค๊ณ ๋งํ ์ ์๋ค.
์์๋ก ๋ณด๋๊ฒ ์ ์ผ ์ดํด๊ฐ ๋น ๋ฅผ ๊ฒ์ด๋ค.
A | B | ๋ฉ์น๊ฐ ํฐ ์ฌ๋ | |
ํค | 180 | 170 | A |
๋ชธ๋ฌด๊ฒ | 70 | 60 | |
ํค | 180 | 175 | A == B |
๋ชธ๋ฌด๊ฒ | 75 | 80 |
๊ทธ๋ ๋ค๋ฉด ํค์ ๋ชธ๋ฌด๊ฒ์ ๋ํ ๋ฐฐ์ด์ ๊ฐ๊ฐ ์์ฑํ๊ณ , ๋ฐ๋ณต๋ฌธ์ ๋๋ ค์ ๊ฐ ์ฌ๋์ ํค์ ๋ชธ๋ฌด๊ฒ๋ฅผ ๋น๊ตํด์
๋ฉ์น๊ฐ ํฐ ์ฌ๋์ rank๋ฅผ ์ฆ๊ฐ์์ผ์ ๋ฐ๋ณต๋ฌธ ๋ง์ง๋ง์ ์ถ๋ ฅ์์ผ ์ฃผ๋ฉด ๋๋ค.
์ฝ๋๋ก ๊ตฌํ ํด๋ณด์.
์ฝ๋ ๊ตฌํ
์ ๋ ฅ๊ณผ ์ถ๋ ฅ์ BufferedReader, BufferedWriter ๋ฅผ ์ฌ์ฉ ํ ๊ฒ์ด๋ค.
public class Main {
public static void main(String[] args) {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
int N = Integer.parseInt(bf.readLine()); // ๋ช ๋ช
์ธ์ง ์
๋ ฅ N
int[] weights = new int[N];
int[] heights = new int[N];
int x,y;
for (int i = 0; i < N; i++) {
st = new StringTokenizer(bf.readLine());
x = Integer.parseInt(st.nextToken());
y = Integer.parseInt(st.nextToken());
weights[i] = x;
heights[i] = y;
}
..
}
}
๋น๊ต ํ๊ธฐ
rank ๋ณ์๋ฅผ ํ๋ ์ ์ธ ํด์ฃผ๊ณ , ๋ฐ๋ณต๋ฌธ์ผ๋ก ๋ชจ๋ ์๋ฅผ ๋ค ๋์์ ๋น๊ต๋ฅผ ํ ๋ค, ์์ ๋ณด๋ค ํค์ ๋ชธ๋ฌด๊ฒ ๋ ๋ค ํด ๊ฒฝ์ฐ์ rank๋ฅผ ์ฆ๊ฐ ์์ผ์ค๋ค.
public static void main(String[] args) {
..
for(int i=0; i<N; i++) {
int rank = 0;
int w1 = weight[i];
int h1 = height[i];
for(int j=0; j<N; j++) {
if(i != j) {
int w2 = weight[j];
int h2 = height[j];
if(w1 < w2 && h1 < h2){
rank++;
}
}
}
bw.write((rank + 1) + " ");
}
bw.flush();
bw.close();
}
์ ์ฒด ์ฝ๋
import java.io.*;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
int N = Integer.parseInt(bf.readLine());
int[] weights = new int[N];
int[] heights = new int[N];
for (int i = 0; i < N; i++) {
st = new StringTokenizer(bf.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
weights[i] = x;
heights[i] = y;
}
for (int i = 0; i < N; i++) {
int rank = 0;
int w1 = weights[i];
int h1 = heights[i];
for (int j = 0; j < N; j++) {
if (i != j) {
int w2 = weights[j];
int h2 = heights[j];
if (w1 < w2 && h1 < h2) {
rank++;
}
}
}
bw.write(rank + 1 + " ");
}
bw.flush();
bw.close();
}
}
๋ฐ์ํ