-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1-kokeunho #1
1-kokeunho #1
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
κ³ μνμ ¨μ΅λλ€~
kokeunho/ꡬν/1-kokeunho.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ’ννλ©΄μμ μ΄λν λ°©ν₯μ λκ°μ λ°°μ΄λ‘ λνλ΄λ λ°©μ μ€λλ§μ 보λ κ² κ°μ΅λλ€.
μ€κ°μ€κ° λ΄ μ€μ ν offsetκ·μΉ(xκ° col, yκ° row λ±)μ κΉλ¨Ήμ΄μ ν·κ°λ Έλ μ μ΄ μλ λ¬Έμ μ νμ΄λΌμ ν λ² νμ΄λ΄€μ΅λλ€.
μ΄ν΄νκΈ° μ½κ² μλμ½λλ₯Ό μμ±νμ¬μ μλμ½λλ₯Ό 보면μ c++λ‘ λΉ λ₯΄κ² ν μ μμμ΅λλ€.
κ·Έλ¦¬κ³ μ λμ½λμ μ μ κ΄κ³κ° λ§€λ² ν·κ°λ Έλλ° μ΄λ² κΈ°νμ νμ€ν μκ² λ κ² κ°μ΅λλ€!
int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[8] = {0, 0, -1, 1, 1, 1, -1, -1};
void getPosition(string& pos, int& x, int & y){
x = pos[0] - 'A' + 1;
y = pos[1] - '0';
}
bool moveStone(int dir){
int sx_ = sx + dx[dir];
int sy_ = sy + dy[dir];
if (sx_ < 1 || sx_ > 8 || sy_ < 1 || sy_ > 8) return false;
sx = sx_;
sy = sy_;
return true;
}
void moveKing(int dir){
int kx_ = kx + dx[dir];
int ky_ = ky + dy[dir];
if (kx_ < 1 || kx_ > 8 || ky_ < 1 || ky_ > 8) return;
if (kx_ == sx && ky_ == sy)
if (!moveStone(dir)) return;
kx = kx_;
ky = ky_;
}
λ¬Έμ νΈλλ°λ μ ν μ§μ₯μμ§λ§ λ³μλͺ μ΄ SX SYλ₯Ό StoneX StoneY King κ³Όκ°μ΄ μ‘°κΈ λ μ§κ΄μ μ΄λ©΄ μ’μκ²κ°μ΅λλ€. λ€λ₯Έμ μ μ½λ κ°κ²°νκ³ κΉλνκ²κ°μ΅λλ€! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
κ³ μνμ ¨μ΅λλ€!! μ λ μ λλ¦λλ‘ νμ΄λ³΄μμ΄μ :)
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
// μΌμͺ½ μλλ₯Ό {0, 0} μΌλ‘ μ€μ
unordered_map<string, pair<int, int>> dir = {
{"R",{1, 0} },
{"L",{-1, 0} },
{"B",{0, -1} },
{"T",{0, 1} },
{"RT",{1, 1} },
{"LT",{-1, 1} },
{"RB",{1, -1} },
{"LB",{-1, -1} }
};
int king[2];
int stone[2];
int n;
vector<string> moves;
void readInput()
{
string str;
cin >> str;
king[0] = str[0] - 'A';
king[1] = str[1] - '1';
cin >> str;
stone[0] = str[0] - 'A';
stone[1] = str[1] - '1';
cin >> n;
moves.resize(n);
for (int i = 0; i < n; i++)
cin >> moves[i];
}
bool moveStone(string index) {
int stoneX = stone[0] + dir[index].first;
int stoneY = stone[1] + dir[index].second;
if(stoneX < 0 || stoneX > 7 || stoneY < 0 || stoneY > 7) return false;
stone[0] = stoneX;
stone[1] = stoneY;
return true;
}
void moveKing(string index)
{
int kingX = king[0] + dir[index].first;
int kingY = king[1] + dir[index].second;
if (kingX < 0 || kingX > 7 || kingY < 0 || kingY > 7) return;
if (kingX == stone[0] && kingY == stone[1])
if (!moveStone(index)) return;
king[0] = kingX; king[1] = kingY;
}
int main()
{
readInput();
for (int i = 0; i < n; i++)
moveKing(moves[i]);
cout << (char)('A' + king[0]) << (char)('1' + king[1]) << '\n';
cout << (char)('A' + stone[0]) << (char)('1' + stone[1]);
return 0;
}
νμ΄λ³΄λλ° μ’ μ€λ μκ°μ μΌλ€μ...
μλμ½λ λμ λ‘μ§ κ΅¬νμ μ½κ² νμ§λ§ μ λ ₯λ°μ Stringκ°μ μ΄λ»κ² directionμΌλ‘ 맀νμν¬μ§ κ³ λ―Όνλλ° μκ°μ μ’ μΌμ΅λλ€. μ λ cppμ unordered_mapμ μ¬μ©ν΄μ νλ²μ λ¬Άμ΄λ²λ Έμ΅λλ€..!
π λ¬Έμ λ§ν¬
[BOJ - νΉ] (https://www.acmicpc.net/problem/1063)
βοΈ μμλ μκ°
1μκ° λ°μ λ κ±Έλ¦° κ² κ°μ΅λλ€
β¨ μλ μ½λ
νΉκ³Ό λ λͺ¨λ μμΉλ₯Ό λ³κ²½
νΉλ§ μμΉλ₯Ό λ³κ²½
π μλ‘κ² μκ²λ λ΄μ©
μ¬μ€ νμ΄μ¬μ μμνμ§ μΌλ§ μλΌμ κ·Έλλ§ λ§λ§ν΄λ³΄μ΄λ λ¬Έμ λ‘ νμ΄λ΄€μ΅λλ€.
νμ΄μ¬ λ¬Έλ² λͺ κ°λ₯Ό λ°°μ μ΅λλ€.
그리κ³
μ΄λ¬ν λ°©μμΌλ‘ λ°©ν₯μ λ°λΌ x, y μ’ν μ΄λμ 맀ν? νλ λ°©λ²λ λ°°μ μ΅λλ€.