반응형
https://www.acmicpc.net/problem/1063
String 은 어렵다
//1063
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
using namespace std;
int kc, sc, kr, sr, N;
char c;
char a;
char arr[51][3];
int dy[4] = { 1,0,-1,0 };
int dx[4] = { 0,-1,0,1 };
int rex, rey, resx, resy;
int dirFlag;
//strcmp
void move(int kx, int ky, int sx, int sy, int num) {
int nx = kx; int ny = ky; int snx = sx; int sny = sy;
rex = kx, rey = ky, resx = sx, resy = sy;
if (strcmp(arr[num], "R") == 0) {
nx = kx + dx[0];
ny = ky + dy[0];
if (nx == sx && ny == sy) {
snx = sx + dx[0];
sny = sy + dy[0];
}
}
else if (strcmp(arr[num], "L") == 0) {
nx = kx + dx[2];
ny = ky + dy[2];
if (nx == sx && ny == sy) {
snx = sx + dx[2];
sny = sy + dy[2];
}
}
else if (strcmp(arr[num], "B") == 0) {
nx = kx + dx[1];
ny = ky + dy[1];
if (nx == sx && ny == sy) {
snx = sx + dx[1];
sny = sy + dy[1];
}
}
else if (strcmp(arr[num], "T") == 0) {
nx = kx + dx[3];
ny = ky + dy[3];
if (nx == sx && ny == sy) {
snx = sx + dx[3];
sny = sy + dy[3];
}
}
else if (strcmp(arr[num], "RT") == 0) { //동북
nx = kx + dx[0] + dx[3];
ny = ky + dy[0] + dy[3];
if (nx == sx && ny == sy) {
snx = sx + dx[0] + dx[3];
sny = sy + dy[0] + dy[3];
}
}
else if (strcmp(arr[num], "LT") == 0) { // 서북
nx = kx + dx[2] + dx[3];
ny = ky + dy[2] + dy[3];
if (nx == sx && ny == sy) {
snx = sx + dx[2] + dx[3];
sny = sy + dy[2] + dy[3];
}
}
else if (strcmp(arr[num], "RB") == 0) {//동남
nx = kx + dx[0] + dx[1];
ny = ky + dy[0] + dy[1];
if (nx == sx && ny == sy) {
snx = sx + dx[0] + dx[1];
sny = sy + dy[0] + dy[1];
}
}
else if (strcmp(arr[num], "LB") == 0) {//서남
nx = kx + dx[2] + dx[1];
ny = ky + dy[2] + dy[1];
if (nx == sx && ny == sy) {
snx = sx + dx[2] + dx[1];
sny = sy + dy[2] + dy[1];
}
}
if (nx <= 0 || ny <= 0 || nx > 8 || ny > 8 || snx <= 0 || sny <= 0 || snx > 8 || sny > 8) {
nx = kx; ny = ky;
snx = sx, sny = sy;
}
resx = snx; resy = sny;
rex = nx; rey = ny;
}
int main() {
scanf("%c", &c);
kc = c - 'A'+1;
scanf("%1d", &kr);
kr = kr;
scanf(" %c", &c);
sc = c - 'A'+1;
scanf("%1d", &sr);
sr = sr ;
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%s", &arr[i]);
}
rex = kr; rey = kc;
resx = sr, resy = sc;
for (int i = 0; i < N; i++) {
move(rex, rey, resx, resy, i);
}
char aa = rey-1 + 'A';
char bb = resy-1 + 'A';
printf("%c", aa);
printf("%d", rex);
printf("\n");
printf("%c", bb);
printf("%d", resx);
}
반응형
'CS > 알고리즘' 카테고리의 다른 글
백준 19238 스타트 택시(우선순위큐) (0) | 2020.10.02 |
---|---|
백준 16235 나무 재테크(시뮬) (0) | 2020.05.12 |
백준 17822 원판 돌리기(시뮬) (0) | 2020.05.06 |
백준 17140 이차원 배열과 연산(시뮬) (0) | 2020.05.06 |
백준 17825 주사위 윷놀이(시뮬+dfs) (0) | 2020.05.06 |