E.cpp 763 B

123456789101112131415161718192021222324252627282930313233
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int MINE = 9;
  4. int main() {
  5. int n, m, k;
  6. while (cin >> n >> m >> k) {
  7. int B[n + 2][m + 2] = {0};
  8. while (k--) {
  9. int x, y;
  10. cin >> x >> y;
  11. B[x + 1][y + 1] = MINE;
  12. }
  13. for (int i = 1; i <= n; i++)
  14. for (int j = 1; j <= m; j++) {
  15. if (B[i][j] == MINE) continue;
  16. int cnt = 0;
  17. for (int x = i - 1; x <= i + 1; x++)
  18. for (int y = j - 1; y <= j + 1; y++)
  19. if (B[x][y] == MINE) ++cnt;
  20. B[i][j] = cnt;
  21. }
  22. for (int i = 1; i <= n; i++) {
  23. for (int j = 1; j <= m; j++)
  24. if (B[i][j] == MINE)
  25. cout << '*';
  26. else
  27. cout << B[i][j];
  28. cout << endl;
  29. }
  30. cout << endl;
  31. }
  32. return 0;
  33. }