-
카테고리
-
세부 분야
알고리즘 · 자료구조
-
해결 여부
미해결
씨름선수 문제 이중for문 통과했습니다.. 정상인건가요?
23.06.15 18:49 작성 조회수 189
0
일단 먼저 풀어봤는데, 객체지향으로 풀려고 Player라는 클래스를 생성 후 몸무게와 키를 저장해 이중 for문으로 풀었는데 통과해버렸습니다.
해당 코드는 150~200ms정도가 나오는데 통과하는게 정상인건지 궁금해서 여쭤봅니다.
import java.util.Scanner;
class Player {
int height;
int weight;
public Player(int height, int weight) {
this.height = height;
this.weight = weight;
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Player[] players = new Player[n];
for (int i = 0; i < n; i++) {
int height = sc.nextInt();
int weight = sc.nextInt();
Player player = new Player(height, weight);
players[i] = player;
}
System.out.println(solution(n, players));
}
private static int solution(int n, Player[] players) {
int answer = n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (players[i].height < players[j].height && players[i].weight < players[j].weight) {
answer--;
break;
}
}
}
return answer;
}
}
답변을 작성해보세요.
답변 1