結果

提出番号 915
提出者 data9824
言語 C++
提出日時 2017-08-01 15:44:03
問題名 (42)オセロ
結果 AC
点数 100%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 AC 100% 2ms 7968KB
2 AC 100% 1ms 7984KB
3 AC 100% 8ms 8336KB
4 AC 100% 2ms 7952KB
5 AC 100% 2ms 7712KB

ソースコード

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
	vector<string> board(8);
	for (int i = 0; i < 8; ++i) {
		cin >> board[i];
	}
	int c;
	cin >> c;
	char color = (c == 0) ? 'b' : 'w';
	string position;
	cin >> position;
	int x0 = position[0] - 'A';
	int y0 = position[1] - '1';
	int dx[] = { -1, -1, 0, 1, 1, 1, 0, -1 };
	int dy[] = { 0, -1, -1, -1, 0, 1, 1, 1 };
	board[y0][x0] = color;
	for (int i = 0; i < 8; ++i) {
		vector<string> saved(board);
		bool flipped = false;
		int x = x0 + dx[i];
		int y = y0 + dy[i];
		while (x >= 0 && x < 8 && y >= 0 && y < 8) {
			if (board[y][x] == '-') {
				break;
			}
			else if (board[y][x] != color) {
				board[y][x] = color;
			}
			else {
				flipped = true;
				break;
			}
			x += dx[i];
			y += dy[i];
		}
		if (!flipped) {
			board = saved;
		}
	}
	for (int i = 0; i < 8; ++i) {
		cout << board[i] << endl;
	}
	return 0;
}