夢追い人

"It takes a dreamer to make a dream come true."―Vincent Willem van Gogh

MineField

class MineField {
public:
   vector <string> getMineField( string mineLocations ) {
		vector<string> map;
		for (int i=0; i<9; i++) map.push_back("000000000");
		for (int i=0; i<mineLocations.length(); i++) {
			if (mineLocations[i] == '(') {
				string temp = "";
				int x, y;
				for (i+=1;;i++) {
					if (mineLocations[i]==',') break;
					temp += mineLocations[i];
				}
				stringstream ss;
				ss << temp; ss >> x;
				temp = "";
				for (i+=1;;i++) {
					if (mineLocations[i]==')') break;
					temp += mineLocations[i];
				}
				stringstream s2;
				s2 << temp; s2 >> y;
				map[x][y] = 'M';
			}
		}
		int dx[] = {-1,0,1};
		int dy[] = {-1,0,1};
		for (int i=0; i<map.size(); i++) {
			for (int j=0; j<9; j++) {
				if (map[i][j]=='M') continue;
				int cnt = 0;
				for (int k=0; k<3; k++) for (int l=0; l<3; l++) {
					if (k == 1 && l == 1) continue;
					int nx = dx[k]+i, ny = dy[l]+j;
					if (nx < 9 && nx >= 0 && ny < 9 && ny >= 0 && map[nx][ny] == 'M')
						cnt++;
				}
				map[i][j] = cnt + '0';
			}
		}
		return map;
   }
};
広告を非表示にする