Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions 이코테/06 정렬/두_배열의_원소_교체/준호.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import java.util.Arrays;
import java.util.Scanner;

public class 준호 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

int N = scanner.nextInt();
int K = scanner.nextInt();

int[] A = new int[N];
int[] B = new int[N];
for (int i = 0; i < N; i++) {
A[i] = scanner.nextInt();
}
for (int i = 0; i < N; i++) {
B[i] = scanner.nextInt();
}

int answer = 0;

Arrays.sort(A);
Arrays.sort(B);

for (int i = 0; i < K; i++) {
int temp = A[i];
A[i] = B[N - i - 1];
B[N - i - 1] = temp;
// 정렬후 교환한 A[i] 보다 A[i+1]이 같거나 크면 더 교환할 이유가 없음.
if (A[i] <= A[i + 1]) {
break;
}
}

for (int i = 0; i < N; i++) {
answer += A[i];
}
System.out.println(answer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import java.util.*;

public class 준호 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
scanner.nextLine();
String[][] examples = new String[N][2];
for (int i = 0; i < N; i++) {
String[] split = scanner.nextLine().split(" ");
examples[i][0] = split[0];
examples[i][1] = split[1];
}
Arrays.sort(examples, Comparator.comparingInt(o -> Integer.parseInt(o[1])));

for (int i = 0; i < N; i++) {
System.out.print(examples[i][0] + " ");
}
}
}