// ccsk_161_049.c
/*
C/C++の宿題片付けます 161代目
http://t...content-available-to-author-only...h.net/test/read.cgi/tech/1354070278/49
[1] 授業単元:計算機実習
[2] 問題文(含コード&リンク): http://c...content-available-to-author-only...d.org/eMHdX9DL
上記のプログラムを変更して,キーボードから(x, y)の座標とマスの状態を入力し,反映するようにしなさい.
入力の際には座標や状態が範囲を超えていないか確認し,越えているときにはもう一度入力するようにしなさい.
[3] 環境
[3.1] OS:Linux
[3.2] コンパイラ名とバージョン:gcc
[3.3] 言語:C
[4] 期限:12/4
*/
#include<stdio.h>
#define YOKO (8)
#define TATE (8)
#define OKUMONO (2) // 置くものの種類 数
int plot[TATE][YOKO];
char *state[] = { " ", "○ ", "● " }; // , "◎", "◇", "◆", ,,,
////////////////////////////////////////////////////////
// [func] 表示
void print_board()
{
int x, y;
printf(" +--+--+--+--+--+--+--+--+\n"); for (y = 0; y < TATE; y++) {
for (x = 0; x < YOKO; x++) {
printf("%s|", state
[plot
[y
][x
]]); }
printf(" +--+--+--+--+--+--+--+--+\n"); }
}
////////////////////////////////////////////////////////
// [func] set
// [arg] x, y : 置きたい場所
// s : 置きたいもの (0, 1, 2 ,,,)
// [ret] 0 : 置けたので置いた
// -1 : 座標が範囲外なので置けない
// -2 : sが不正
// ( -3 : 既に何かが置いてあるので置けない )未実装
int set(int x, int y, int s)
{
// check
if (x < 0 || YOKO <= x || y < 0 || TATE <= y) {
return -1;
}
#if 1
if (s < 0 || OKUMONO < s) { // 何でも置ける
return -2;
}
#else
if (s < 1 || OKUMONO < s) { // reversi mode
return -2;
}
if (plot[y][x]) {
return -3;
}
#endif
// set
plot[y][x] = s;
// reversi
; //未実装
// end
return 0;
}
////////////////////////////////////////////////////////
// main
int main()
{
int x, y, s;
char b[256];
// 初期化
for (y = 0; y < TATE; y++) {
for (x = 0; x < YOKO; x++) {
plot[y][x] = 0;
}
}
print_board();
// 入力
while (1) {
printf("input x y state(1-%d) ('q' to quit)\n", OKUMONO
); fgets(b
, sizeof(b
), stdin
); if (b[0] == 'q') {
break;
}
sscanf(b
, "%d %d %d", &x
, &y
, &s
); if (set(x, y, s)) {
} else {
// 表示
print_board();
// 勝敗判定
; // 未実装
}
}
// 終了
;
}
// End of ccsk_161_049.c
Ly8gY2Nza18xNjFfMDQ5LmMKLyoKICAgIEMvQysr44Gu5a6/6aGM54mH5LuY44GR44G+44GZIDE2MeS7o+ebrgogICAgaHR0cDovL3QuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLmgubmV0L3Rlc3QvcmVhZC5jZ2kvdGVjaC8xMzU0MDcwMjc4LzQ5CiAgICAgICAgWzFdIOaOiOalreWNmOWFg++8muioiOeul+apn+Wun+e/kiAKICAgICAgICBbMl0g5ZWP6aGM5paHKOWQq+OCs+ODvOODiSbjg6rjg7Pjgq8p77yaIGh0dHA6Ly9jLi4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi5kLm9yZy9lTUhkWDlETAogICAgICAgIOS4iuiomOOBruODl+ODreOCsOODqeODoOOCkuWkieabtOOBl+OBpu+8jOOCreODvOODnOODvOODieOBi+OCiSh4LCB5KeOBruW6p+aomeOBqOODnuOCueOBrueKtuaFi+OCkuWFpeWKm+OBl++8jOWPjeaYoOOBmeOCi+OCiOOBhuOBq+OBl+OBquOBleOBhO+8jgogICAgICAgIOWFpeWKm+OBrumam+OBq+OBr+W6p+aomeOChOeKtuaFi+OBjOevhOWbsuOCkui2heOBiOOBpuOBhOOBquOBhOOBi+eiuuiqjeOBl++8jOi2iuOBiOOBpuOBhOOCi+OBqOOBjeOBq+OBr+OCguOBhuS4gOW6puWFpeWKm+OBmeOCi+OCiOOBhuOBq+OBl+OBquOBleOBhO+8jgogICAgICAgIFszXSDnkrDlooMgCiAgICAgICAg44CAWzMuMV0gT1PvvJpMaW51eCAKICAgICAgICDjgIBbMy4yXSDjgrPjg7Pjg5HjgqTjg6nlkI3jgajjg5Djg7zjgrjjg6fjg7PvvJpnY2MgCiAgIC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8vLy8vLy8vLy8vLy8vLy8vLy8KLy8gW2Z1bmNdICAgc2V0Ci8vIFthcmddICAgIHgsIHkgOiDnva7jgY3jgZ/jgYTloLTmiYAKLy8gICAgICAgICAgcyAgICA6IOe9ruOBjeOBn+OBhOOCguOBriAoMCwgMSwgMiAsLCwpCi8vIFtyZXRdICAgIDAgICAgOiDnva7jgZHjgZ/jga7jgafnva7jgYTjgZ8KLy8gICAgICAgICAgLTEgICA6IOW6p+aomeOBjOevhOWbsuWkluOBquOBruOBp+e9ruOBkeOBquOBhAovLyAgICAgICAgICAtMiAgIDogc+OBjOS4jeatowovLyAgICAgICAgKCAtMyAgIDog5pei44Gr5L2V44GL44GM572u44GE44Gm44GC44KL44Gu44Gn572u44GR44Gq44GEICnmnKrlrp/oo4UKaW50IHNldChpbnQgeCwgaW50IHksIGludCBzKQp7CiAgICAvLyBjaGVjawogICAgaWYgKHggPCAwIHx8IFlPS08gPD0geCB8fCB5IDwgMCB8fCBUQVRFIDw9IHkpIHsKICAgICAgICByZXR1cm4gLTE7CiAgICB9CiNpZiAxCiAgICBpZiAocyA8IDAgfHwgT0tVTU9OTyA8IHMpIHsgLy8g5L2V44Gn44KC572u44GR44KLCiAgICAgICAgcmV0dXJuIC0yOwogICAgfQojZWxzZQogICAgaWYgKHMgPCAxIHx8IE9LVU1PTk8gPCBzKSB7IC8vIHJldmVyc2kgbW9kZQogICAgICAgIHJldHVybiAtMjsKICAgIH0KICAgIGlmIChwbG90W3ldW3hdKSB7CiAgICAgICAgcmV0dXJuIC0zOwogICAgfQojZW5kaWYKICAgIC8vIHNldAogICAgcGxvdFt5XVt4XSA9IHM7CgogICAgLy8gcmV2ZXJzaQogICAgOyAgICAgICAgICAgICAgICAgICAgICAgICAgIC8v5pyq5a6f6KOFCgogICAgLy8gZW5kCiAgICByZXR1cm4gMDsKfQoKLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8KLy8gICAgICBtYWluCmludCBtYWluKCkKewogICAgaW50IHgsIHksIHM7CiAgICBjaGFyIGJbMjU2XTsKCiAgICAvLyDliJ3mnJ/ljJYKICAgIGZvciAoeSA9IDA7IHkgPCBUQVRFOyB5KyspIHsKICAgICAgICBmb3IgKHggPSAwOyB4IDwgWU9LTzsgeCsrKSB7CiAgICAgICAgICAgIHBsb3RbeV1beF0gPSAwOwogICAgICAgIH0KICAgIH0KICAgIHByaW50X2JvYXJkKCk7CgogICAgLy8g5YWl5YqbCiAgICB3aGlsZSAoMSkgewogICAgICAgIHByaW50ZigiaW5wdXQgIHggIHkgc3RhdGUoMS0lZCkgICgncScgdG8gcXVpdClcbiIsIE9LVU1PTk8pOwogICAgICAgIGZnZXRzKGIsIHNpemVvZihiKSwgc3RkaW4pOwogICAgICAgIGlmIChiWzBdID09ICdxJykgewogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgc3NjYW5mKGIsICIlZCAlZCAlZCIsICZ4LCAmeSwgJnMpOwogICAgICAgIGlmIChzZXQoeCwgeSwgcykpIHsKICAgICAgICAgICAgcHJpbnRmKCJlcnJvclxuIik7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgLy8g6KGo56S6CiAgICAgICAgICAgIHByaW50X2JvYXJkKCk7CiAgICAgICAgICAgIC8vIOWLneaVl+WIpOWumgogICAgICAgICAgICA7ICAgICAgICAgICAgICAgICAgIC8vIOacquWun+ijhQogICAgICAgIH0KICAgIH0KCiAgICAvLyDntYLkuoYKICAgIDsKfQoKLy8gRW5kIG9mICBjY3NrXzE2MV8wNDkuYw==