Skip to content
Merged

DSLR #114

Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions maywngml/[5]๋ฐฑ์ค€/9019_DSLR.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
#define MAX 10000

int A, B;
bool visited[MAX];

string bfs() {
int tempNum;
queue<pair<int, string>> q;
//ํ์— n๊ณผ ํ˜„์žฌ๊นŒ์ง€์˜ ๋ช…๋ น์–ด๋ฅผ ์ €์žฅ
q.push({ A, "" });
visited[A] = true;

while (!q.empty()) {
int num = q.front().first;
string str = q.front().second;
q.pop();

if (num == B)
return str;

//๋ช…๋ น์–ด๊ฐ€ D์ผ ๊ฒฝ์šฐ
tempNum = (num * 2) % 10000;
if (!visited[tempNum]) {
q.push({ tempNum, str + "D" });
visited[tempNum] = true;
}
//๋ช…๋ น์–ด๊ฐ€ S์ผ ๊ฒฝ์šฐ
if (num == 0)
tempNum = 9999;
else
tempNum = num - 1;
if (!visited[tempNum]) {
q.push({ tempNum, str + "S" });
visited[tempNum] = true;
}
//๋ช…๋ น์–ด๊ฐ€ L์ผ ๊ฒฝ์šฐ
tempNum = (num % 1000) * 10 + (num / 1000);
if (!visited[tempNum]) {
q.push({ tempNum, str + "L" });
visited[tempNum] = true;
}
//๋ช…๋ น์–ด๊ฐ€ R์ผ ๊ฒฝ์šฐ
tempNum = (num % 10) * 1000 + num / 10;
if (!visited[tempNum]) {
q.push({ tempNum, str + "R" });
visited[tempNum] = true;
}
}
}

int main() {
int T;
vector<string> answer;

cin >> T;

for (int i = 0; i < T; i++) {
cin >> A >> B;
answer.push_back(bfs());
memset(visited, 0, sizeof(visited));
}

for (auto elem : answer) {
cout << elem << '\n';
}
}