- ํด๋น ๋ฌธ์ ๋ฅผ ํ๋ฉด์ ๋จ๊ธด ๋ฉ๋ชจ๋ค์ issue์์ ์ฒดํฌํ๊ธฐ.
zzanzu / acmicpc Goto Github PK
View Code? Open in Web Editor NEW์จ-๊ณ -๋ฆฌ-๋ฌ-๐
์จ-๊ณ -๋ฆฌ-๋ฌ-๐
package bfs;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Problem11724 {
static int N, M;
static boolean[][] map;
static boolean[] visited;
static boolean[] check;
static Queue<Integer> queue;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
M = sc.nextInt();
map = new boolean[N+1][N+1];
visited = new boolean[N+1];
check = new boolean[N+1];
queue = new LinkedList<>();
for(int i = 0; i < M; i++) {
int u = sc.nextInt();
int v = sc.nextInt();
map[u][v] = true;
map[v][u] = true;
check[u] = true;
check[v] = true;
}
int count = 0;
for(int i = 1; i <= N; i++) {
if(check[i] == true && visited[i] == false) {
// 0. ํ์๋ค๊ฐ ์์ ์ง์ ๋ฃ์ด์ฃผ
queue.add(i);
// 0. ์์์ง์ ๋ฐฉ๋ฌธ ๊ธฐ๋ก ๋จ๊ธฐ
visited[i] = true;
while(queue.isEmpty() == false) {
// 1. ํ์์ ๊บผ๋ด์ค๊ธฐ
int current = queue.poll();
// 2. ์ฐ๊ฒฐ๋ ๊ธธ๋ค ์ฐพ๊ธฐ
for(int j = 1; j <= N; j++) {
// 3. ๊ฐ ์ ์๋ ๊ธธ ์ฐพ๊ธฐ
if(map[current][j] == true && visited[j] == false) {
// 4. ํ์ ๋ฃ๊ธฐ(๊ฐ ์ ์๋ ๊ณณ)
queue.add(j);
// 5. ๋ฐฉ๋ฌธ ์ฒดํฌ(๊ฐ ์ ์๋ ๊ณณ)
visited[j] = true;
}
}
}
count++;
} else if(check[i] == false) {
count++;
}
}
System.out.println(count);
}
}
๊ทผ๋ฐ ๋๋ฌด ๋ณต์กํ๊ฒ ์งฐ๋ค...
package example03;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Problem7576 {
static int N, M;
static int[][] visited; // ์ต์ ์๊ธฐ์ ์๊ฐ
static int[][] map;
static Queue<Position3> queue;
static int[] dx = {-1, 1, 0, 0};
static int[] dy = {0, 0, -1, 1};
static int max = Integer.MIN_VALUE;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
M = sc.nextInt();
N = sc.nextInt();
map = new int[N][M];
visited = new int[N][M];
queue = new LinkedList<>();
for(int y = 0 ; y < N; y++) {
for(int x = 0; x < M; x++) {
map[y][x] = sc.nextInt();
}
}
// ์ฉ์ํ ๋งํ ๊ฐ ์๋ ์์น ํ์ ์ ์ฅ
for(int y = 0 ; y < N; y++) {
for(int x = 0; x < M; x++) {
if(map[y][x] == 1) {
Position3 pos = new Position3(x, y, 1);
visited[y][x] = 1;
queue.add(pos);
}
}
}
while(queue.isEmpty() == false) {
Position3 currentPos = queue.poll();
visited[currentPos.y][currentPos.x] = currentPos.time;
if(max < currentPos.time) {
max = currentPos.time;
}
for(int i = 0; i < 4; i++) {
int targetX = currentPos.x + dx[i];
int targetY = currentPos.y + dy[i];
if(targetX >= 0 && targetX < M && targetY >= 0 && targetY < N) {
if(map[targetY][targetX] != -1 && map[targetY][targetX] == 0) {
if(visited[targetY][targetX] == 0) {
Position3 nextPos = new Position3(targetX, targetY, currentPos.time + 1);
queue.add(nextPos);
}
}
}
}
}
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
if(visited[i][j] == 0 && map[i][j] == 0) {
System.out.println(-1);
return;
}
}
}
System.out.println(max-1);
}
}
class Position3 {
int y;
int x;
int time;
public Position3(int x, int y, int time) {
this.y = y;
this.x = x;
this.time = time;
}
}
while(queue.isEmpty() == false) {
Position3 currentPos = queue.poll();
if(max < currentPos.time) {
max = currentPos.time;
}
for(int i = 0; i < 4; i++) {
int targetX = currentPos.x + dx[i];
int targetY = currentPos.y + dy[i];
if(targetX >= 0 && targetX < M && targetY >= 0 && targetY < N) {
if(map[targetY][targetX] != -1 && map[targetY][targetX] == 0) {
if(visited[targetY][targetX] == 0) {
Position3 nextPos = new Position3(targetX, targetY, currentPos.time + 1);
queue.add(nextPos);
visited[targetY][targetX] = currentPos.time+1;
}
}
}
}
}
์ด ๋ฌธ์ ๋ ์๊ฐ ์ด๊ณผ๋ ๋ฐํ์ ์๋ฌ๋ฅผ ์ด๋ป๊ฒ ์ค์ด๋๋๊ฐ ๊ด๊ฑด์ด๋ค
์ผ๋จ์ ๋ง๋๊ธฐ ๋ฐฐ์ด์ ์ค๋ฆ์ฐจ์์ผ๋ก ์ ๋ ฌํด์ฃผ๊ณ ,
๋งจ ์ฒ์์ผ๋ก ์๊ฐํ ์ ์๋ ๋ฐฉ๋ฒ์,
while(start < end) {
int sum = length[start] + length[end];
if(length > N) {
end--:
} else if(length < N) {
start++;
} else {
find = true;
break;
}
}
if(find == true) {
sysout(yes ~~);
else {
sysout("danger");
}
Employee[] data = new Employee[5];
data[0] = new Employee(1,2);
data[1] = new Employee(5,4);
data[2] = new Employee(4,5);
data[3] = new Employee(3,3);
data[4] = new Employee(2,1);
...
Arrays.sort(data);
}
class Employee implements Comparable<Employee> { // 'Employee๋ Employee์ ๋น๊ต ๊ฐ๋ฅํ๋ค'์ ์๋ฏธ
int rank1;
int rank2;
public Employee(int rank1, int rank2) {
this.rank1 = rank1;
this.rank2 = rank2;
}
@Override
public String toString() {
return "Employee [rank1=" + rank1 + ", rank2=" + rank2 + "]";
}
@Override
public int compareTo(Employee arg0) {
// this - ๋ ์์ , arg0 - ๋น๊ต ๋์
return Integer.compare(this.rank1, arg0.rank1); // ๋ ์์ (this)์ ๋ค๋ฅธ ๊ฒ(arg0)์ ๋น๊ตํ๋ค
}
}
Arrays.sort(data, new Comparator<Employee>() {
@Override
public int compare(Employee arg0, Employee arg1) {
return Integer.compare(arg0.rank1, arg1.rank1);
}
});
or
// comparator๋ฅผ ๋งค๋ฒ ์์ฑํ๊ธฐ ๋ฒ๊ฑฐ๋ก์ฐ๋๊น ๋ฏธ๋ฆฌ ๋ง๋ค์ด๋๊ณ ์ฐ๊ธฐ
Comparator<Employee> cc = new Comparator<Employee>() {
@Override
public int compare(Employee arg0, Employee arg1) {
return Integer.compare(arg0.rank1, arg1.rank1);
}
};
Arrays.sort(data, cc);
class Employee {
int rank1;
int rank2;
public Employee(int rank1, int rank2) {
this.rank1 = rank1;
this.rank2 = rank2;
}
@Override
public String toString() {
return "Employee [rank1=" + rank1 + ", rank2=" + rank2 + "]";
}
}
public class SortingTest {
public static void main(String[] args) {
Employee[] data = new Employee[5];
data[0] = new Employee(1,2);
data[1] = new Employee(5,4);
data[2] = new Employee(4,5);
data[3] = new Employee(3,3);
data[4] = new Employee(2,1);
System.out.println(Arrays.toString(data));
Comparator<Employee> cc = new Comparator<Employee>() {
@Override
public int compare(Employee arg0, Employee arg1) {
return Integer.compare(arg0.rank1, arg1.rank1);
}
};
ArrayList<Employee> list = new ArrayList<>();
for(int i = 0; i < data.length; i++) {
list.add(data[i]);
}
System.out.println(data);
list.sort(cc);
}
}
class Employee {
int rank1;
int rank2;
public Employee(int rank1, int rank2) {
this.rank1 = rank1;
this.rank2 = rank2;
}
@Override
public String toString() {
return "Employee [rank1=" + rank1 + ", rank2=" + rank2 + "]";
}
}
https://www.acmicpc.net/problem/2178
์ฐ์ ์ DFS๋ก ํ์ด๋ด.
static int[] dx = {-1, 1, 0, 0};
static int[] dy = {0, 0, -1, 1};
...
// 2. ์ฐ๊ฒฐ๋ ๊ธธ์ ์ฐพ๋๋ค.(์ํ์ข์ฐ, 4๊ฐ์ง) dx, dy๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ ์ง์ค!
for(int i = 0; i < 4; i++) {
int targetX = x + dx[i];
int targetY = y + dy[i];
ํ ์์น์์ ์,ํ,์ข,์ฐ๋ฅผ ํ์ํ๊ธฐ ์ํด ํ์ฌ ์์น (x, y)์ ๋ฏธ๋ฆฌ ์ ์ํ ํ์ ์ขํ ์ด๋๊ฑฐ๋ฆฌ dx, dy๋ฅผ ์ ์ํด์ for๋ฌธ์์์ ํ์
์ฑ์ ์์ผ๋ก๋ ์๊ฐ ์ด๊ณผ
package example02;
import java.util.Arrays;
import java.util.Scanner;
public class Problem2178 {
static int N, M;
static int[][] map;
static boolean[][] visited;
static int[] dx = {-1, 1, 0, 0};
static int[] dy = {0, 0, -1, 1};
static int min = Integer.MAX_VALUE;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
M = sc.nextInt();
sc.nextLine();
// ๊ทธ๋ํ์ ๋
ธ๋์ ๋ฒํธ๊ฐ 1,2,3 ์ด๋ฐ๊ฒ ์๋๋ผ์ ๊ทธ๋ฅ N,M ์จ์ค
map = new int[N][M];
visited = new boolean[N][M];
// ์ฌ๊ธฐ์ int๋ก String์ ํ ๊ธ์๋ฅผ ๋ฐ์๋ณด๋ ๋ฐฉ์ ใ
ใ
for(int y = 0; y < N; y++) {
String temp = sc.nextLine();
for(int x = 0; x < M; x++) {
if(temp.charAt(x) == '1') {
map[y][x] = 1;
} else {
map[y][x] = 0;
}
}
}
dfs(0, 0, 1);
System.out.println(min);
}
public static void dfs(int x, int y, int current) {
// 0. ๋ชฉ์ ์ง ๋๋ฌ ์ฌ๋ถ ์ฒดํฌ , ์ด ๋ถ๋ถ์ ์๊ฐ ๋ชปํจ!
if(y == N-1 && x == M-1) {
if(current < min) {
min = current;
}
return; // ์ธ๋ฐ์๋ ๊ธธ ํ์ ์ํ๊ฒ ํด์ค
}
// 1. ๋ฐฉ๋ฌธ ๊ธฐ๋ก์ ๋จ๊ธด๋ค.
visited[y][x] = true;
// 2. ์ฐ๊ฒฐ๋ ๊ธธ์ ์ฐพ๋๋ค.(์ํ์ข์ฐ, 4๊ฐ์ง) dx, dy๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ ์ง์ค!
for(int i = 0; i < 4; i++) {
int targetX = x + dx[i];
int targetY = y + dy[i];
if(targetX >= 0 && targetX < M && targetY >= 0 && targetY < N) {
// 3. ๊ฐ ์ ์๋ ๊ธธ์ ์ฐพ๋๋ค.
if(map[targetY][targetX] == 1 && visited[targetY][targetX] == false){
// 4. ๊ฐ๋ค
dfs(targetX, targetY, current+1);
}
}
}
// 5. ๋ฐฉ๋ฌธ ํด์ง
visited[y][x] = false;
}
}
๊ทผ๋ฐ ์ฌ๊ธฐ์ visited๋ฅผ intํ์ผ๋ก ๋ฐ๊ฟ์ ๊ฐ ์นธ์ด ๋ฐฉ๋ฌธ์ด ๋์์ ๋ ๊ฑฐ๊ธฐ๋ฅผ ์ง๋๊ฐ ๋น์์ ๊ฑฐ๋ฆฌ(current)๋ฅผ ์ ์ฅํ๊ฒ ๋๋ค. ๊ทธ๋ฌ๋ฉด ๋ค์๋ฒ์ ๊ทธ ์นธ์ ์ง๋๊ฐ๊ฒ ๋์์ ๋์ current์ visited(์ด์ ์ ๋ฐฉ๋ฌธ์ ๊ฑฐ๋ฆฌ)๋ฅผ ๋น๊ตํ๋ค.
public static void dfs(int x, int y, int current) {
// 0. ๋ชฉ์ ์ง ๋๋ฌ ์ฌ๋ถ ์ฒดํฌ , ์ด ๋ถ๋ถ์ ์๊ฐ ๋ชปํจ!
if(y == N-1 && x == M-1) {
if(current < min) {
min = current;
}
return; // ์ธ๋ฐ์๋ ๊ธธ ํ์ ์ํ๊ฒ ํด์ค
}
// 1. ๋ฐฉ๋ฌธ ๊ธฐ๋ก์ ๋จ๊ธด๋ค.
visited[y][x] = current;
// 2. ์ฐ๊ฒฐ๋ ๊ธธ์ ์ฐพ๋๋ค.(์ํ์ข์ฐ, 4๊ฐ์ง) dx, dy๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ ์ง์ค!
for(int i = 0; i < 4; i++) {
int targetX = x + dx[i];
int targetY = y + dy[i];
if(targetX >= 0 && targetX < M && targetY >= 0 && targetY < N) {
// 3. ๊ฐ ์ ์๋ ๊ธธ์ ์ฐพ๋๋ค.
if(map[targetY][targetX] == 1){
if(visited[targetY][targetX] == 0 || visited[targetY][targetX] > current+1)
// 4. ๊ฐ๋ค
dfs(targetX, targetY, current+1);
}
}
}
// 5. ๋ฐฉ๋ฌธ ํด์ง
// visited[y][x] = 0;
}
'1. ๋ฐฉ๋ฌธ ๊ธฐ๋ก์ ๋จ๊ธด๋ค' ๋จ๊ณ์์ ๋ฐฉ๋ฌธ ์ฌ๋ถ๋ฅผ ์ ์ฅํ๋ ๊ฒ์ด ์๋๋ผ, ํด๋น ์์น๊น์ง์ ๊ฑฐ๋ฆฌ๋ฅผ ์ ์ฅํ๋ค
๊ทธ๋ ๊ฒ ๋๋ฉด ๋ค์๋ฒ์ ํด๋น ์์น๋ฅผ ๋ค์ ํ ๋ฒ ๋ฐฉ๋ฌธํ๊ฒ ๋์์ ๋, ์ด ๊ฐ(visited)์ current์ ๋น๊ตํ์ฌ ํ์์ ๋ ํ ์ง ๊ฒฐ์ ํ๊ฒ ๋๋ค.
๋ฐฉ๋ฌธ ํด์ง๋ ํ์ง ์๋๋ค!
๋ฐฐ์ด.indexOf( )
๋ฐฐ์ด.lastIndexOf( ) ์ฌ์ฉํ๊ธฐ
์นด๋์ ์๊น๊ณผ ์ซ์๋ฅผ ๋ณด๊ณ 5์ฅ์ ์นด๋์ ์๊น๊ณผ ์ซ์์ ํน์ง๋ค์ ๊ฐ์ง๊ณ ๋ฌธ์ ๋ฅผ ํ๊ฒ ๋๋ค.
๋ฐ๋ผ์ ์นด๋์ ์๊น๊ณผ ์ซ์์ ํน์ง๋ค์ ์ ์ฅํ๋ ๋ฐฐ์ด์ ๊ฐ๊ฐ ๋ง๋ค๊ณ , ๊ฐ ์ธ๋ฑ์ค๋ ์ถํ ํ์๋ฅผ ์ธ๊ฒ ๋๋ค.
์ด๋ฐ ๋ฐฉ์์ผ๋ก ์นด๋์ ์๊น(color)์ ์ซ์(num)์ ๋ํ ๊ฐ ํ์๋ฅผ ์นด์ดํธํ ๋ฐฐ์ด์ ๋ง๋ ๋ค.
public class Problem11403 {
static int N;
static int[][] map;
static int[][] result;
static boolean[] visited;
static Queue<Integer> queue;
static boolean[] isExist;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
map = new int[N+1][N+1];
result = new int[N][N];
visited = new boolean[N+1];
queue = new LinkedList<>();
isExist = new boolean[N+1];
for(int y = 1; y <= N; y++) {
for(int x = 1; x <= N; x++) {
map[y][x] = sc.nextInt();
if(map[y][x] == 1) isExist[y] = true;
}
}
for(int y = 1; y <= N; y++) {
visited = new boolean[N+1];
if(isExist[y] == true) {
// 0. ํ์๋ค๊ฐ ์์ ์ง์ ๋ฃ์ด์ฃผ๊ธฐ
queue.add(y);
// 0. ์์ ์ง์ ๋ฐฉ๋ฌธ ์ฒดํฌํ๊ธฐ
// visited[y] = true; // ๋ฐฉ๋ฌธ์ฒดํฌํ๋ ํ์ด๋ฐ์ด ๊ด๊ฑด์ด๊ตฐ
while(queue.isEmpty() == false) {
// 1. ํ์์ ๊บผ๋ด์ค๊ธฐ
int current = queue.poll();
// 2. ์ฐ๊ฒฐ๋ ๊ธธ ์ฐพ๊ธฐ
for(int i = 1; i <= N; i++) {
// 3. ๊ฐ ์ ์๋ ๊ธธ ์ฐพ๊ธฐ
if(map[current][i] == 1 && visited[i] == false) {
// 4. ํ์ ๋ฃ๊ธฐ
queue.add(i);
visited[i] = true; // ์ฌ๊ธฐ์ ๋ฐฉ๋ฌธ์ฒดํฌ!
result[y-1][i-1] = 1;
}
}
}
}
}
for(int i = 0; i < N; i++) {
for(int j = 0; j < N; j++) {
System.out.print(result[i][j] + " ");
}
System.out.println();
}
}
}
๋ผ๊ณ ํ๋ค๋ฉด,
๋ฐฑํธ๋ํน์ ์ฒ์๊ณผ ๋ง์ง๋ง์ ๋จ๊ณ๊ฐ ์ถ๊ฐ๋์๋ค.
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class Problem1987 {
static Set<Integer> set;
static int R, C;
static int[][] map;
static int[] dx = {0, 0, 1, -1};
static int[] dy = {1, -1, 0, 0};
static int max = Integer.MIN_VALUE;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
set = new HashSet<>();
R = sc.nextInt();
C = sc.nextInt();
map = new int[R][C];
for(int i = 0; i < R; i++) {
String temp = sc.next();
for(int j = 0 ; j < C; j++) {
map[i][j] = temp.charAt(j);
}
}
set.add(map[0][0]);
dfs(0, 0, 1);
System.out.println(max);
}
static void dfs(int x, int y, int count) {
// 0. ์ข
๋ฃ ์ฒดํฌ
if(count > max) {
max = count;
}
// 1. ๋ฐฉ๋ฌธ ์ฒดํฌ
set.add(map[y][x]);
// 2. ์ฐ๊ฒฐ๋ ๊ธธ ์ฒดํฌ
for(int i = 0; i < 4; i++) {
int targetX = x + dx[i];
int targetY = y + dy[i];
// 3. ๊ฐ ์ ์๋ ๊ธธ ์ฒดํฌ
if(targetX >= 0 && targetX < C && targetY >= 0 && targetY < R) {
if(!set.contains(map[targetY][targetX])) {
// 4. ๊ฐ๋ค
dfs(targetX, targetY, count+1);
}
}
}
// 5. ๋ฐฉ๋ฌธ ์ฒดํฌ ํด์
set.remove(map[y][x]);
}
}
์๋๋๋ก๋ผ๋ฉด visited ๋ฐฐ์ด์ ์ ์ธํด์ ํ์ํ ์ํ๋ฒณ์ ํ์ํด์ฃผ๊ณ
์ข
๋ฃ ์ฌ๋ถ๋ฅผ ์ฒดํฌํ๊ธฐ์ํด ์ด๊ฑธ ๋ณด๊ณ ๋งค๋ฒ ์ฒดํฌํ์ ๊ฒ์ด๋ค.
ํ์ง๋ง ๊ฐ์ฌ๋๊ป์ Set๋ผ๋ ์๋ฃ๊ตฌ์กฐ๋ฅผ ์๊ฐํด์ฃผ์
จ๊ณ ,
์ด๊ฒ์ ํน์ง์ ์๋ฃ๋ฅผ ์ ์ฅํ ๋(add) ์ค๋ณต์ ํ๋ฝํ์ง ์๊ณ ์ ์ฅํ๊ธฐ ๋๋ฌธ์
์ด ๋ฌธ์ ์ ์ ํฉํ๋ค๊ณ ํ์
จ๋ค. ํนํ contains()ํจ์๋ฅผ ํตํด set์ ๋ด๊ฐ ํ์ํ๋ ์ํ๋ฒณ์ด
๊ธฐ์กด์ ์ ์ฅ๋์๋์ง(ํ์ํ์๋์ง) ํ์ธํ๊ธฐ ์ฝ๊ธฐ ๋๋ฌธ์ ์ฝ๋๋ฅผ ๊ตฌํํ๊ธฐ ๋ ๊ฐ๋จํด์ก๋ค.
Set<Integer> set = new HashSet<>();
set.add(์ถ๊ฐํ ๋ฐ์ดํฐ);
set.contains(์ฐพ๊ณ ์ํ๋ ๋ฐ์ดํฐ); // ์๋์ง ์๋์ง ์ฒดํฌ
set.remove(์ง์ฐ๊ณ ์ํ๋ ๋ฐ์ดํฐ);
์จ-๊ณ -๋ฆฌ-๋ฌ-ํ-์ด-ํ
๋ง์ ์ ์ฒญ ๋ฐ๋๋๋ค.
package example04;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
public class Problem1759 {
static int L, C;
static Character[] data;
static boolean[] visited;
static LinkedList<String> result;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
L = sc.nextInt();
C = sc.nextInt();
data = new Character[C];
visited = new boolean[C];
for (int i = 0; i < C; i++) {
String temp = sc.next();
data[i] = temp.charAt(0);
}
Arrays.sort(data);
result = new LinkedList<String>();
for (int i = 0; i < data.length - 3; i++) {
if (isVow(data[i])) {
Password pwd = new Password(data[i], 1, 0, 1, "" + data[i]);
dfs(pwd);
} else {
Password pwd = new Password(data[i], 1, 1, 0, "" + data[i]);
dfs(pwd);
}
}
for(String r : result) {
System.out.println(r);
}
}
public static void dfs(Password pwd) {
Password currentPwd = pwd;
// 0. ์ข
๋ฃ ์กฐ๊ฑด ์ฒดํฌ
if (currentPwd.depth == L) { // ์ด๋ถ๋ถ์ 4๋ก ํ์๋ค;;
if (currentPwd.con >= 2 && currentPwd.vow >= 1) {
// ๊ฒฐ๊ณผ ์ ์ฅ
result.add(currentPwd.pwd);
}
}
// 1. ๋ฐฉ๋ฌธ ์ฒดํฌ
visited[check(currentPwd.current)] = true;
// 2. ์ฐ๊ฒฐ๋ ๊ธธ
for (int i = check(currentPwd.current); i < data.length; i++) {
// 3. ๊ฐ ์ ์๋ ๊ธธ
if (visited[i] == false) {
// 4. ๊ฐ๋ค.
if (isVow(data[i])) {
Password nextPwd = new Password(data[i], currentPwd.depth + 1,
currentPwd.con, currentPwd.vow + 1, currentPwd.pwd + data[i]);
dfs(nextPwd);
} else {
Password nextPwd = new Password(data[i], currentPwd.depth + 1,
currentPwd.con + 1, currentPwd.vow, currentPwd.pwd + data[i]);
dfs(nextPwd);
}
}
}
// ๋ฐฑํธ๋ํน!
visited[check(currentPwd.current)] = false;
}
// data ๋ฐฐ์ด๋ด์์ ํด๋น ๋ฌธ์์ index๋ฅผ ๋ฆฌํดํ๋ค.
public static int check(char c) {
for (int i = 0; i < data.length; i++) {
if (c == data[i]) {
return i;
}
}
return -1;
}
// ๋ชจ์ ์ฒดํฌ
public static boolean isVow(char c) {
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
return true;
}
return false;
}
}
class Password {
char current;
int depth;
int con; // ์์
int vow; // ๋ชจ์
String pwd;
public Password(char current, int depth, int con, int vow, String pwd) {
this.current = current;
this.depth = depth;
this.con = con;
this.vow = vow;
this.pwd = pwd;
}
@Override
public String toString() {
return "Password [current=" + current + ", depth=" + depth + ", con=" + con + ", vow=" + vow + ", pwd=" + pwd
+ "]";
}
}
์กฐ์ฌํฉ์๋ค.
ArrayList?
LinkedList?
Queue?
๊ฐ๊ฐ์ ํน์ง, ์ฌ์ฉ๋ฒ์ ๋ํด ๊ณต๋ถํด๋ณด์
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.