회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
IllegalArgument 진짜 모르겠습니다.
7568번 - 덩치
pmsu2008
2년 전
0
compareTo 에서 오류가 나는 것이라고 예상되나, 어떻게 바꿔줘야 할 지 모르겠습니다 ㅜ.ㅜ
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; /*** * 백준 7568번 * 덩치 * 2024-03-16 * 시간 제한 : 1초 * 메모리 제한 : 128MB */ public class Main { static int N; // 2 <= N <= 50 static int h, w; static Map<People, Integer> peoples = new LinkedHashMap<>(); public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; N = Integer.parseInt(br.readLine()); for (int i = 0; i < N; i++) { st = new StringTokenizer(br.readLine()); w = Integer.parseInt(st.nextToken()); h = Integer.parseInt(st.nextToken()); peoples.put(new People(w, h), 0); } List<People> sorted = new ArrayList<>(peoples.keySet()); Collections.sort(sorted); int rank = 0; w = Integer.MAX_VALUE; h = Integer.MAX_VALUE; int time = 1; for (int i = 0; i < N; i++) { People p = sorted.get(i); if (w > p.w && h > p.h) { w = p.w; h = p.h; rank += time; peoples.put(p, rank); time = 1; } else { peoples.put(p, rank); time++; } } StringBuilder sb = new StringBuilder(); for (People p : peoples.keySet()) { sb.append(peoples.get(p)).append(" "); } System.out.println(sb); } public static class People implements Comparable<People> { int h; int w; public People(int h, int w) { this.h = h; this.w = w; } @Override public int compareTo(People o) { if (this.h > o.h && this.w > o.w) return -1; else if (this.h < o.h && this.w < o.w) return 1; return 0; } } }
댓글을 작성하려면
로그인
해야 합니다.
pmsu2008 2년 전
compareTo 에서 오류가 나는 것이라고 예상되나, 어떻게 바꿔줘야 할 지 모르겠습니다 ㅜ.ㅜ