Solved.ac Class3+
public class Main {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int size = Integer.parseInt(br.readLine());
int[] data = new int[size];
String[] stringData = br.readLine().split(" ");
for (int i = 0; i < size; i++) {
data[i] = Integer.parseInt(stringData[i]);
}
int[] copyData = Arrays.copyOf(data, data.length);
Arrays.sort(copyData);
Map<Integer, Integer> rankMap = new HashMap<>();
int count = 0;
for (int i = 0; i < size; i++) {
if (!rankMap.containsKey(copyData[i])) {
rankMap.put(copyData[i], count++);
}
}
for (int i = 0; i < size; i++) {
sb.append(rankMap.get(data[i])).append(" ");
}
System.out.println(sb);
}
}
성공
fun main() {
print(MainToKotlin().solve())
}
class MainToKotlin {
fun solve() :String{
val stringBuilder = StringBuilder()
val size = readln().toInt()
val data = mutableListOf<Int>()
val stringData = readln().split(" ")
for (d in stringData) {
data.add(d.toInt())
}
val sortedData = data.sorted()
val rankMap = mutableMapOf<Int, Int>()
var count = 0
for (i in 0..<size) {
if (!rankMap.containsKey(sortedData[i])) {
rankMap.put(sortedData[i], count++)
}
}
for (i in 0..<size) {
stringBuilder.append(rankMap[data[i]]).append(" ")
}
return stringBuilder.toString()
}
}