fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int w, h, res = 0;
  6. cin >> w >> h;
  7. char **x = new char *[h];
  8. for (int i = 0; i < h; i++) x[i] = new char[w];
  9. for (int i = 0; i < h; i++) {
  10. for (int j = 0; j < w; j++) {
  11. cin >> x[i][j];
  12. }
  13. }
  14. for (int i = 0; i < h; i++) {
  15. for (int j = 0; j < w - 1; j++) {
  16. if (x[i][j] != x[i][j + 1]) res++;
  17. }
  18. }
  19. for (int i = 0; i < h - 1; i++) {
  20. for (int j = 0; j < w; j++) {
  21. if (x[i][j] != x[i + 1][j]) res++;
  22. }
  23. }
  24. cout << res << endl;
  25. return 0;
  26. }
Success #stdin #stdout 0s 15232KB
stdin
6 5
AABBBB
BBBBBB
BBBAAA
AAAAAA
AAAAAA
stdout
10