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 4790f76

Browse files
week2 3problems
1 parent 7e0b731 commit 4790f76

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed
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;

0 commit comments

Comments
(0)

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