import java.util.Scanner;
public class Main {
public static int[] dx = new int[]{ 1, 0, -1, 0 };
public static int[] dy = new int[]{ 0, -1, 0, 1 };
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
int x = 0;
int y = 0;
int current = 3;
for(int i = 0; i < str.length(); i++){
if(str.charAt(i) == 'L') {
current = ( current - 1 + 4 ) % 4;
}else if(str.charAt(i) == 'R') {
current = ( current + 1 ) % 4;
}else if(str.charAt(i) == 'F'){
x = x + dx[current];
y = y + dy[current];
}
}
System.out.printf("%d %d", x, y);
}
}
- 반시계 방향일 경우, -1이 나올 경우를 고려하여 + 4 해준다음 %4 로 나머지 잡아줌.
- 왼쪽일 경우, 반시계 방향
- 오른쪽일 경우, 시계 방향
728x90
반응형
'Algorithm > 자료 구조 및 개념 정리' 카테고리의 다른 글
달팽이 순회 (0) | 2023.06.05 |
---|---|
격자 탐색 템플릿 (0) | 2023.05.20 |
이진트리 순회 (0) | 2022.09.06 |
Array와 LinkedList의 차이 (0) | 2022.07.10 |
LinkedList (0) | 2022.07.10 |