比较水的一题,找到方法就好说了。
#include <iostream> using namespace std; char tab[128][128]; int main() { int h, w; while (cin >> h >> w){ cin.get(); for (int i = 0; i < h; ++i ) cin >> tab[i]; int cnt = 0; for (int i = 0; i < h; ++i){ for (int j = 0; j < w; ++j){ if (tab[i][j] != '.') ++cnt; else{ int f = 0; for (int k = 0; k < j; ++k){ if (tab[i][k] != '.') ++f; } if (f % 2) cnt += 2; } } } cout << cnt / 2 << endl; } return 0; }