Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
Tags
- 공개키 암호화
- 알고리즘
- 자료구조
- sql
- til
- Java
- spring
- mysql
- js
- 항해99
- 정렬
- 위상정렬
- generic class
- 개발자취업
- jsp
- 코테
- dbms
- LeetCode
- 가상컴퓨팅
- 코딩테스트준비
- 코딩테스트
- Sort
- JPA
- DB
- javascript
- 99클럽
- Algorithm
- python
- 99클럽 #코딩테스트준비 #개발자취업 #항해99 #til
- 크루스칼
Archives
- Today
- Total
PLOD
[백준] 좌표 압축(18870) 본문
🔗 문제 링크
https://www.acmicpc.net/problem/18870
✅ 코드
import java.io.*;
import java.util.*;
public class 백준_18870 {
static int n;
static HashMap<Integer, Integer> map;
static int[] arr;
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
arr = new int[n];
map = new HashMap<>();
st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
int[] sortedArr = arr.clone();
Arrays.sort(sortedArr);
int rank = 0;
for(int i = 0 ; i < n ; i++){
if(!map.containsKey(sortedArr[i])){
map.put(sortedArr[i], rank++);
}
}
for(int i = 0; i < n ;i++){
System.out.print(map.get(arr[i]) + " ");
}
br.close();
}
}
💡 배운 점 & 느낀 점
1. int[] sortedArr = arr.clone() → Java는 Call By Value 이기 때문에 배열을 복사하려면 Clone 메서드 사용해야 함
'대외 활동 및 IT 지식 > 알고리즘 문제 풀이 정리' 카테고리의 다른 글
| [Leetcode] 187. Repeated DNA Sequences (0) | 2026.03.23 |
|---|---|
| [Leetcode] 2283. Check if Number Has Equal Digit Count and Digit Value (0) | 2026.03.20 |
| [백준] 파일 정리(20291) (0) | 2026.03.09 |
| [백준] 식당 메뉴(26043) (0) | 2026.02.25 |
| [백준] 큐(10843) (0) | 2026.02.22 |
Comments