Skip to content

Commit

Permalink
2024-03-18
Browse files Browse the repository at this point in the history
  • Loading branch information
Me-in-U committed Mar 18, 2024
1 parent 7579a0b commit 4edbd20
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
9 changes: 5 additions & 4 deletions BOJ-ios/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## โœ๏ธ ๊ธฐ๋ก
## โœ๏ธ ๊ธฐ๋ก

| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
| :---: | :--------: | :------: | :---------------------------------------------------: | :------------------------------------------------------: |
| 1์ฐจ์‹œ | 2024.03.18 | ํŠธ๋ผ์ด | [์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก](https://www.acmicpc.net/problem/5052) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pulls/2) |

| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
|:----:|:---------:|:----:|:-----:|:----:|
| 1์ฐจ์‹œ | 2023.10.27 | BFS | - | - |
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package BAEKJOON.Gold.Gold_IV.P5052๋ฒˆ_์ „ํ™”๋ฒˆํ˜ธ_๋ชฉ๋ก;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
public static class Contact {
Contact[] contacts;
boolean exists;

Contact() {
contacts = new Contact[10];
}

public boolean addContacts(String phoneNumber) {
int digit = phoneNumber.charAt(0) - '0';
if (this.contacts[digit] == null) {
this.contacts[digit] = new Contact();
} else if (this.contacts[digit].exists) {
return false;
}
if (phoneNumber.length() == 1) {
this.contacts[digit].exists = true;
} else {
return this.contacts[digit].addContacts(phoneNumber.substring(1, phoneNumber.length()));
}
return true;
}
}

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
StringBuilder sb = new StringBuilder();
for (int i = 0; i < T; i++) {
Contact root = new Contact();
int N = Integer.parseInt(br.readLine());
String[] numbers = new String[N];
for (int j = 0; j < N; j++)
numbers[j] = br.readLine();
Arrays.sort(numbers);
boolean able = true;
for (int j = 0; j < N; j++) {
if (!root.addContacts(numbers[j])) {
able = false;
break;
}
}
sb.append(able ? "YES" : "NO").append('\n');
}
System.out.print(sb.toString());
}
}

0 comments on commit 4edbd20

Please sign in to comment.