poj 1656 Counting Black
来源:互联网 发布:网络技术发展 编辑:程序博客网 时间:2024/04/26 19:46
//简单的模拟题,按部就班地按照题目的意思做就很容易了,给定一定范围,将这范围内的地方涂黑或者涂白,最后统计黑色方格的个数! #include <iostream>#include <string>using namespace std;int grid[105][105];int main(){ int i, j, tc, x, y, l, boardx, boardy, ans = 0; string str; for (i = 1; i <= 100; i++) for (j = 1; j <= 100; j++) grid[i][j] = 0; cin >> tc; while (tc--) { cin >> str >> x >> y >> l; boardx = x+l-1; boardy = y+l-1; if (str == "BLACK") { for (i = x; i <= boardx; i++) for (j = y; j <= boardy; j++) { if (grid[i][j] == 0) grid[i][j] = 1; } } else if (str == "WHITE") { for (i = x; i <= boardx; i++) for (j = y; j <= boardy; j++) { if (grid[i][j] == 1) grid[i][j] = 0; } } else if (str == "TEST") { for (i = x; i <= boardx; i++) for (j = y; j <= boardy; j++) { if (grid[i][j] == 1) ans++; } cout << ans << endl; ans = 0; } } system("pause");}