inflearn logo
강의

Course

Instructor

Introduction to Java Algorithm Problem Solving: Coding Test Preparation

1. Wrestler

씨름 O(n)으로 풀었는데 런타임 에러가 떠요

292

yungjoon2

7 asked

0

package GreedyAlgorithm;

import java.util.*;

public class SsireumSelection {
static Scanner sc = new Scanner(System.in);
static ArrayList<Body> athlete = new ArrayList<>();
static int n = sc.nextInt();
static int answer;
static int maxWeight=Integer.MIN_VALUE;
public static void main(String[] args) {
for (int i = 0; i < n; i++) {
athlete.add(new Body(sc.nextInt(), sc.nextInt()));
}
Collections.sort(athlete);
for (Body b : athlete) {
if (b.weight > maxWeight) {
answer++;
maxWeight=b.weight;
}
}
System.out.println(answer);
}
public static class Body implements Comparable<Body> {
public int height;
public int weight;

public Body(int height, int weight) {
this.height = height;
this.weight = weight;
}

@Override
public int compareTo(Body o) {
return o.height - this.height;
}
}

}

90ms~126ms, 26mb 나옵니다

java 코딩-테스트

Answer 2

0

yungjoon2

죄송합니다. 분명 Main으로 했었던것같은데... 아무튼 감사합니다...!!

0

codingcamp

안녕하세요^^

클래스의 이름을 Main으로 해야 합니다.

import java.util.*;

public class Main {
static Scanner sc = new Scanner(System.in);
static ArrayList<Body> athlete = new ArrayList<>();
static int n = sc.nextInt();
static int answer;
static int maxWeight=Integer.MIN_VALUE;
public static void main(String[] args) {
for (int i = 0; i < n; i++) {
athlete.add(new Body(sc.nextInt(), sc.nextInt()));
}
Collections.sort(athlete);
for (Body b : athlete) {
if (b.weight > maxWeight) {
answer++;
maxWeight=b.weight;
}
}
System.out.println(answer);
}
public static class Body implements Comparable<Body> {
public int height;
public int weight;

public Body(int height, int weight) {
this.height = height;
this.weight = weight;
}

@Override
public int compareTo(Body o) {
return o.height - this.height;
}
}

}

안녕하세요. 바뀐 채점사이트 관련해서 문의드립니다.

0

39

2

갑자기 채점 사이트가 바뀌었어요

0

36

1

문제 리스트 페이지

0

30

1

채점 사이트 관련 질문드립니다

0

24

1

봉우리 문제 질문입니다

0

87

2

씨름 선수 문제에서 각 선수의 몸무게나 키가 같을 수도 있다면?

0

66

0

이 코드랑 영상 코드중에 뭐가 더 좋은 코드인가요?

0

72

0

가중치 방향 그래프에서 가중치가 0인 간선을 표현하는 방법

0

68

1

좌표 정렬 문제 이 코드가 왜 틀린지 모르겠습니다 ㅠㅠ

0

85

2

6-7 강의에서

0

48

1

6-6. 장난꾸러기 질문 있습니다.

0

46

1

강의 수강후 코딩테스트

0

111

1

answer 변수 사용 여부

0

47

1

2중 for문

1

85

2

2-11. 임시반장정하기 (Runtime Error)

0

63

1

혹시 LinkedList 같은 자료 구조들은 따로 배우지 않나요?

0

70

1

이런 풀이는 어떨까요

0

44

1

자바 스트림 방식의 효율성 질문 드립니다.

0

59

1

알고리즘 자료 구조들..

0

63

1

StringBuilder vs BufferdWriter

0

49

1

원더랜드(프림)

0

50

1

이런 코드는 어떤가요?

0

62

1

bfs 풀이

0

57

1

병합정렬

0

58

1