Mysterious Game
破壊的に更新する事になるので、Cでも良いかと。
#include <stdio.h> int main() { int m,n; int map[21][21]; int rbX, rbY; while(1) { scanf("%d",&n); if(n == 0) break; int i; int x,y; //initialize map for(y = 0; y < 21; y++) { for(x = 0; x < 21; x++) { map[y][x] = 0; } } for(i = 0; i < n; i++) { scanf("%d %d",&x,&y); map[y][x] = 1; } rbX = 10; rbY = 10; scanf("%d",&m); char d; int j; int k; for(i = 0; i < m; i++) { scanf(" %c %d",&d,&j); printf("rbX: %d\n",rbX); switch(d) { case 'N': for(k = 0; k <= j; k++) { map[rbY+k][rbX] = 0; } rbY += j; break; case 'E': for(k = 0; k <= j; k++) { map[rbY][rbX+k] = 0; } rbX += j; break; case 'S': for(k = 0; k <= j; k++) { map[rbY-k][rbX] = 0; } rbY -= j; break; case 'W': for(k = 0; k <= j; k++) { map[rbY][rbX-k] = 0; } rbX -=j; break; default: break; } } //Check if all gem collected or not int collectedp = 1; for(y = 0; y < 21; y++) { for(x = 0; x < 21; x++) { if(map[y][x] == 1) { collectedp = 0; } } } if(collectedp) { printf("Yes\n"); } else { printf("No\n"); } } return 0; }