Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7e0b731

Browse files
week1: 1 problem
1 parent cd7eec6 commit 7e0b731

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

‎YoungjinShin/1주차/BOJ 16455.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
implemented with normal sort - bad time complexity
2+
the question is asking for a code that works in less than 0.2s.
3+
need to work with quick selection instead. - similar to quick sort.
4+
5+

‎YoungjinShin/1주차/kthInt.java‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import java.util.*;
2+
3+
public class kthInt{
4+
public static void main (String[] args){
5+
Scanner sc = new Scanner(System.in);
6+
7+
System.out.println("Type the numbers of elements you want to store: ");
8+
int num = sc.nextInt();
9+
int[] nums = new int[num];
10+
11+
System.out.println("Type the elements: ");
12+
for(int i = 0; i<num; i++){
13+
nums[i] = sc.nextInt();
14+
}
15+
System.out.println("Type number of cases you want to test: ");
16+
int cases = sc.nextInt();
17+
int[][] test = new int[cases][3];
18+
19+
System.out.println("Type the elements for each cases: ");
20+
for(int i = 0; i<cases; i++){
21+
for ( int j = 0; j < 3; j++){
22+
test[i][j] = sc.nextInt();
23+
}
24+
}
25+
26+
sc.close();
27+
int [] finalanswer = solution(nums, test);
28+
System.out.println();
29+
System.out.print('[');
30+
for(int i: finalanswer){
31+
32+
if(i == finalanswer[cases-1]){
33+
System.out.print(i);
34+
}else{
35+
System.out.print(i + ",");
36+
}
37+
}
38+
System.out.print(']');
39+
40+
}
41+
42+
public static int[] solution (int [] array, int[][] commands){
43+
int row = commands.length;
44+
int[] answer = new int [row];
45+
for (int i = 0; i < row; i++){
46+
int[] newarr = Arrays.copyOfRange(array, (commands[i][0] - 1) , (commands[i][1]));
47+
Arrays.sort(newarr);
48+
answer[i] = newarr[commands[i][2] - 1];
49+
}
50+
51+
return answer;
52+
}
53+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /