Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. char arr[3000][3000]; int a, b; char all[3000][3000];
  5. bool car()
  6. {
  7. for (int i = 0; i < a-1; i++)
  8. {
  9. for (int j = 0; j < b; j++)
  10. {
  11. if (arr[i][j] == 'X')
  12. {
  13. if (arr[i+1][j] == '#')
  14. return false;
  15. }
  16. }
  17. }
  18. return true;
  19. }
  20. int main() {
  21. ios::sync_with_stdio(false);
  22. cin >> a >> b;
  23. for (int i = 0; i < a; i++)
  24. {
  25. for (int j = 0; j < b; j++)
  26. {
  27. cin >> arr[i][j];
  28. }
  29. }
  30. int k = 0;
  31. while (car())
  32. {
  33. for (int i = 0; i < a; i++)
  34. {
  35. for (int j = 0; j < b; j++)
  36. {
  37. if (i == 0 && k == 0)
  38. all[i][j] = '.';
  39. else if (arr[i][j] != '#')
  40. all[i][j] = arr[i-1][j];
  41. else if (arr[i][j] == '#')
  42. all[i][j] = '#';
  43. else if (i == a-1 && k == 0)
  44. {
  45. all[i][j] = '#'; k++;
  46. }
  47. }
  48. }
  49. memcpy(arr, all, sizeof(arr));
  50. }
  51. for (int i = 0; i < a; i++)
  52. {
  53. for (int j = 0; j < b; j++)
  54. {
  55. cout << arr[i][j];
  56. }
  57. if (i != a-1)
  58. cout << '\n';
  59. }
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement