본문 바로가기

문제 풀기/기타 문제

KickStart 2019 Round C - Wiggle Walk

문제 링크 : https://codingcompetitions.withgoogle.com/kickstart/round/0000000000050ff2/0000000000150aac

 

Kick Start - Google’s Coding Competitions

Hone your coding skills with algorithmic puzzles meant for students and those new to coding competitions. Participate in one round or join them all.

codingcompetitions.withgoogle.com

 

#include <iostream>

int main() {
	int T;
	scanf("%d", &T); ///

	for (int i = 0; i < T; i++) {
		int N, r, c, Rr, Rc;
		scanf("%d %d %d %d %d\n", &N, &r, &c, &Rr, &Rc); ///

		int** board = new int*[r];
		for (int j = 0; j < r; j++) {
			board[j] = new int[c];
		}
		Rr--;
		Rc--;
		board[Rr][Rc] = 1;

		for (int j = 0; j < N; j++) {
			char I;
			scanf("%c", &I); ///
			switch (I) {
			case 'S' :
				while (board[Rr][Rc] == 1) {
					Rr++;
				}
				board[Rr][Rc] = 1;
				break;
			case 'W' :
				while (board[Rr][Rc] == 1) {
					Rc--;
				}
				board[Rr][Rc] = 1;
				break;
			case 'E' :
				while (board[Rr][Rc] == 1) {
					Rc++;
				}
				board[Rr][Rc] = 1;
				break;
			case 'N' :
				while (board[Rr][Rc] == 1) {
					Rr--;
				}
				board[Rr][Rc] = 1;
				break;
			}
		}

		printf("Case #%d: %d %d\n", i + 1, Rr+1, Rc+1);
	}
}

 

// fix
#include <iostream>

int main() {
	int T;
	scanf("%d", &T);
	int N, r, c, Rr, Rc;
	int i, j, k;
	char I;
	bool* board[30000];
	for (j = 0; j < 30000; j++) {
		board[j] = new bool[30000];
	}
	for (i = 0; i < T; i++) {
		scanf("%d %d %d %d %d\n", &N, &r, &c, &Rr, &Rc);
		for (j = 0; j < r; j++) {
			for (k = 0; k < c; k++) {
				board[j][k] = false;
			}
		}
		Rr--;
		Rc--;
		board[Rr][Rc] = true;

		for (j = 0; j < N; j++) {
			scanf("%c", &I);
			switch (I) {
			case 'S':
				while (board[Rr][Rc]) {
					Rr++;
				}
				board[Rr][Rc] = true;
				break;
			case 'W':
				while (board[Rr][Rc]) {
					Rc--;
				}
				board[Rr][Rc] = true;
				break;
			case 'E':
				while (board[Rr][Rc]) {
					Rc++;
				}
				board[Rr][Rc] = true;
				break;
			case 'N':
				while (board[Rr][Rc]) {
					Rr--;
				}
				board[Rr][Rc] = true;
				break;
			}
		}

		printf("Case #%d: %d %d\n", i + 1, Rr + 1, Rc + 1);
	}
}

'문제 풀기 > 기타 문제' 카테고리의 다른 글

KickStart 2019 Round C - Wiggle Walk  (0) 2019.05.27
Kick Start 2019 Round A - Training  (0) 2019.04.29

태그