Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions JHLEE325/202509/17 BOJ G4 DSLR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
```java
import java.io.*;
import java.util.*;

public class Main {

static class Node {
int num;
String cmd;

Node(int num, String cmd) {
this.num = num;
this.cmd = cmd;
}
}

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int T = Integer.parseInt(br.readLine());

for (int t = 0; t < T; t++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int A = Integer.parseInt(st.nextToken());
int B = Integer.parseInt(st.nextToken());

boolean[] visited = new boolean[10000];
Queue<Node> q = new ArrayDeque<>();

q.add(new Node(A, ""));
visited[A] = true;

while (!q.isEmpty()) {
Node cur = q.poll();

if (cur.num == B) {
sb.append(cur.cmd).append("\n");
break;
}

int d = D(cur.num);
if (!visited[d]) {
visited[d] = true;
q.add(new Node(d, cur.cmd + "D"));
}

int s = S(cur.num);
if (!visited[s]) {
visited[s] = true;
q.add(new Node(s, cur.cmd + "S"));
}

int l = L(cur.num);
if (!visited[l]) {
visited[l] = true;
q.add(new Node(l, cur.cmd + "L"));
}

int r = R(cur.num);
if (!visited[r]) {
visited[r] = true;
q.add(new Node(r, cur.cmd + "R"));
}
}
}
System.out.print(sb);
}

static int D(int n) {
return (2 * n) % 10000;
}

static int S(int n) {
return (n == 0) ? 9999 : n - 1;
}

static int L(int n) {
return (n % 1000) * 10 + n / 1000;
}

static int R(int n) {
return (n / 10) + (n % 10) * 1000;
}
}
```