Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5. ifstream odczyt("gra.txt");
  6.  
  7. int main()
  8. {
  9. int licznik=0;
  10. char tab[12][20];
  11. for (int i = 0;i<12;i++)
  12. {
  13. for(int j=0;j<20;j++)
  14. {
  15. odczyt>>tab[i][j];
  16. cout<<tab[i][j];
  17. }
  18. cout<<endl;
  19. }
  20. for(int i = 0;i<12;i++)
  21. {
  22. for (int j = 0 ;i<20;i++)
  23. {
  24. if(tab[i-1][j-1]=='X')
  25. {
  26. licznik++;
  27. }
  28. if(tab[i][j-1]=='X')
  29. {
  30. licznik++;
  31. }
  32. if(tab[i+1][j-1]=='X')
  33. {
  34. licznik++;
  35. }
  36. if(tab[i][j-1]=='X')
  37. {
  38. licznik++;
  39. }
  40. if(tab[i][j+1]=='X')
  41. {
  42. licznik++;
  43. }
  44. if(tab[i+1][j-1]=='X')
  45. {
  46. licznik++;
  47. }
  48. if(tab[i+1][j]=='X')
  49. {
  50. licznik++;
  51. }
  52. if(tab[i+1][j+1]=='X')
  53. {
  54. licznik++;
  55. }
  56. if(licznik==3)
  57. {
  58. tab[i][j]='X';
  59. }
  60. if(licznik>=4 || licznik==0 || licznik==1)
  61. {
  62. tab[i][j]='.';
  63. }
  64.  
  65. }
  66. }
  67. cout<<endl;
  68. cout<<endl;
  69.  
  70. for(int i = 0;i<12;i++)
  71. {
  72. for(int j = 0;j<20;j++)
  73. {
  74. cout<<tab[i][j];
  75. }
  76. cout<<endl;
  77. }
  78. return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement