Advertisement
pasholnahuy

Untitled

Mar 3rd, 2024 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. int n, m;
  8. cin >> m >> n;
  9. vector<vector<char>> mat(m, vector<char>(n, ' '));
  10. int k;
  11. cin >> k;
  12. for (int i = 0; i < k; ++i) {
  13. int x, y;
  14. cin >> x >> y, --x, --y;
  15. mat[x][y] = '*';
  16. }
  17. for (int i = 0; i < m; ++i) {
  18. for (int j = 0; j < n; ++j) {
  19. if (mat[i][j] == '*') {
  20. cout << "* ";
  21. } else {
  22. int cnt = 0;
  23. for (int t = max(i - 1, 0); t <= min(m - 1, i + 1); ++t){
  24. for (int z = max(j - 1, 0); z <= min(n - 1, j + 1); ++z){
  25. cnt += mat[t][z] == '*';
  26. }
  27. }
  28. cout << cnt << ' ';
  29. }
  30. }
  31. cout << '\n';
  32. }
  33. }
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement