📕 문제
📌 링크
![](https://velog.velcdn.com/images/wowns226/post/98c4c66a-a02f-4971-b3ff-bf1c08a465e0/image.png)
📗 접근 방식
- 입력을 받아 정수 배열로 저장
- 배열을 정렬하고 중복된 값을 제거
- 각 값에 대해 순서(압축된 값)를 기록하는 Dictionary를 생성
- 입력된 좌표를 압축된 값으로 변환하여 출력
📘 코드
using System;
using System.Collections.Generic;
namespace BOJ
{
class No_18870
{
static void Main()
{
int n = int.Parse(Console.ReadLine());
int[] inputs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int[] sortedArray = new List<int>(inputs).ToArray();
Array.Sort(sortedArray);
var dict = new Dictionary<int, int>();
int index = 0;
foreach(var value in sortedArray)
{
if(!dict.ContainsKey(value))
{
dict[value] = index;
index++;
}
}
for(int i = 0; i < n; i++)
Console.Write($"{dict[inputs[i]]} ");
}
}
}
📙 오답노트
📒 알고리즘 분류