Advertisement
Guest User

Untitled

a guest
Oct 1st, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int Case = 1;
  8. int n, m;
  9. while (cin >> n >> m, n > 0 && m > 0)
  10. {
  11. // "There must be an empty line between field outputs."
  12. if (Case > 1)
  13. cout << endl;
  14.  
  15. // Use borders around the field.
  16. vector<vector<char> > field(n + 2, vector<char>(m + 2, '.'));
  17. for (int r = 1; r <= n; ++r)
  18. for (int c = 1; c <= m; ++c)
  19. cin >> field[r][c];
  20.  
  21. cout << "Field #" << Case++ << ":" << endl;
  22. for (int r = 1; r <= n; ++r)
  23. {
  24. for (int c = 1; c <= m; ++c)
  25. {
  26. if (field[r][c] == '*')
  27. cout << '*';
  28. else
  29. {
  30. int mines = 0;
  31. for (int i = r - 1; i <= r + 1; ++i)
  32. for (int j = c - 1; j <= c + 1; ++j)
  33. if (field[i][j] == '*')
  34. ++mines;
  35. cout << mines;
  36. }
  37. }
  38. cout << endl;
  39. }
  40. }
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement