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 4b3caab

Browse files
Merge pull request #9 from yjshin229/master
1주차,2주차 문제 업로드
2 parents cd7eec6 + f60e3c1 commit 4b3caab

File tree

8 files changed

+159
-1
lines changed

8 files changed

+159
-1
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+
]

‎YoungjinShin/2주차/NoDuplicates.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.*;
2+
3+
public class NoDuplicates {
4+
public static void main (String []args){
5+
Scanner sc = new Scanner(System.in);
6+
String sentence = sc.nextLine();
7+
sc.close();
8+
9+
String[] splited = sentence.split(" ");
10+
11+
Set<String> str = new HashSet<String>();
12+
13+
String ret = "yes";
14+
for(String s: splited){
15+
if(str.add(s)==false){
16+
ret = "no";
17+
break;
18+
}
19+
}
20+
System.out.println(ret);
21+
22+
23+
}
24+
}

‎YoungjinShin/2주차/contacts.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.util.*;
2+
3+
public class contacts {
4+
public static void main(String [] args){
5+
Scanner sc = new Scanner(System.in);
6+
String numbers = sc.nextLine();
7+
sc.close();
8+
9+
String[] num = numbers.split(",");
10+
System.out.println(solution(num));
11+
}
12+
13+
public static boolean solution(String[] phone_book) {
14+
boolean answer = true;
15+
Arrays.sort(phone_book,Comparator.comparing(String :: length));
16+
17+
for(int i=0; i<phone_book.length; i++){
18+
for(int j = i+1; j < phone_book.length; j++){
19+
if (phone_book[i].equals(phone_book[j].substring(0, phone_book[i].length()))){
20+
answer = false;
21+
break;
22+
}
23+
}
24+
}
25+
26+
return answer;
27+
}
28+
}

‎YoungjinShin/2주차/marathon.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import java.util.*;
2+
3+
public class marathon {
4+
public static void main (String[] args){
5+
Scanner sc = new Scanner(System.in);
6+
System.out.print("Enter the number of participants: ");
7+
int num = sc.nextInt();
8+
String[] participants = new String[num];
9+
10+
System.out.println("Type the name of participants: ");
11+
for(int i = 0; i<num; i++){
12+
participants[i] = sc.next();
13+
}
14+
15+
String[] completions = new String[num-1];
16+
17+
System.out.println("Type the name of the completed ones: ");
18+
for(int i = 0; i<num-1; i++){
19+
completions[i] = sc.next();
20+
}
21+
sc.close();
22+
23+
System.out.println(solution(participants, completions));
24+
}
25+
26+
public static String solution(String[] participant, String[] completion) {
27+
String answer = "";
28+
29+
List<String> newCompletion= Arrays.asList(completion);
30+
List<String> newparticipant= Arrays.asList(participant);
31+
32+
Collections.sort(newCompletion);
33+
Collections.sort(newparticipant);
34+
35+
int index = 0;
36+
for (int i = 0; i< newCompletion.size(); i++){
37+
if (newCompletion.get(i).equals(newparticipant.get(i))==false){
38+
index = i;
39+
break;
40+
}
41+
}
42+
answer = newparticipant.get(index);
43+
44+
return answer;
45+
}
46+
47+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import java.util.Scanner;

‎YoungjinShin/youngjin.java

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
(0)

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