FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-for-coding-test/6/12.java at master · ndb796/python-for-coding-test · GitHub
ndb796
/
python-for-coding-test
Public
Notifications
You must be signed in to change notification settings
Fork
831
Star
2.4k
Code
Issues
129
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-for-coding-test
/
6
/
12.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
49 lines (41 loc) · 1.41 KB
Breadcrumbs
python-for-coding-test
/
6
/
12.java
Copy path
File metadata and controls
49 lines (41 loc) · 1.41 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import
java
.
util
.*;
public
class
Main
{
public
static
void
main
(
String
[]
args
) {
Scanner
sc
=
new
Scanner
(
System
.
in
);
// N과 K를 입력받기
int
n
=
sc
.
nextInt
();
int
k
=
sc
.
nextInt
();
// 배열 A의 모든 원소를 입력받기
Integer
[]
a
=
new
Integer
[
n
];
for
(
int
i
=
0
;
i
<
n
;
i
++) {
a
[
i
] =
sc
.
nextInt
();
}
// 배열 B의 모든 원소를 입력받기
Integer
[]
b
=
new
Integer
[
n
];
for
(
int
i
=
0
;
i
<
n
;
i
++) {
b
[
i
] =
sc
.
nextInt
();
}
// 배열 A는 오름차순 정렬 수행
Arrays
.
sort
(
a
);
// 배열 B는 내림차순 정렬 수행
Arrays
.
sort
(
b
,
Collections
.
reverseOrder
());
// 첫 번째 인덱스부터 확인하며, 두 배열의 원소를 최대 K번 비교
for
(
int
i
=
0
;
i
<
k
;
i
++) {
// A의 원소가 B의 원소보다 작은 경우
if
(
a
[
i
] <
b
[
i
]) {
// 두 원소를 교체
int
temp
=
a
[
i
];
a
[
i
] =
b
[
i
];
b
[
i
] =
temp
;
}
// A의 원소가 B의 원소보다 크거나 같을 때, 반복문을 탈출
else
break
;
}
// 배열 A의 모든 원소의 합을 출력
long
result
=
0
;
for
(
int
i
=
0
;
i
<
n
;
i
++) {
result
+=
a
[
i
];
}
System
.
out
.
println
(
result
);
}
}
Back
|
FazBrowse Home
|
New Git URL