Advertisement
Guest User

gowno

a guest
Dec 15th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. #include <fstream>
  5. #include <iomanip>
  6.  
  7. using namespace std;
  8. const int m=3,n=3;
  9. int licznik_przesuniec=0;
  10. void wypelnianie(int tab[m][n]){
  11. for(int i=0;i<m;i++){
  12. for(int j=0;j<n;j++){
  13. tab[i][j]=-100+rand()%201;
  14. }
  15. }
  16. };
  17.  
  18. void przesuwanie(int tab[m][n]){
  19. int suma=0,temp;
  20. for(int i=0;i<m;i++){
  21. for(int j=0;j<n;j++)
  22. suma=suma+tab[i][j];
  23. if(suma>0){
  24. temp=tab[i][n-1];
  25. for(int b=n-1;b>=0;b--){
  26. tab[i][b]=tab[i][b-1];
  27. }
  28. tab[i][0]=temp;
  29. licznik_przesuniec++;
  30. }
  31. suma=0;
  32.  
  33. }
  34. }
  35.  
  36. void zapis(int tab[m][n], string s){
  37. ofstream plik;
  38. plik.open(s.c_str(), ios::app);
  39. if(plik.good()){
  40. for(int i=0;i<m;i++){
  41. for(int j=0;j<n;j++){
  42. plik<<tab[i][j]<<" ";
  43. }
  44. cout<<endl;
  45. }
  46. plik<<tab[m][n];
  47. }
  48. }
  49.  
  50.  
  51. int main() {
  52.  
  53. int A[m][n], B[m][n];
  54. int tempA,tempB;
  55. string s="tab_A.txt", s1="tab_B.txt";
  56. srand(time(0));
  57. wypelnianie(A);
  58. wypelnianie(B);
  59. przesuwanie(A);
  60. licznik_przesuniec=tempA;
  61. licznik_przesuniec=0;
  62. przesuwanie(B);
  63. licznik_przesuniec=tempB;
  64. zapis(A,s);
  65. zapis(B,s1);
  66. if(tempA>tempB)
  67. cout<<"wiecej przesuniec w tab A";
  68. else
  69. cout<<"wiecej przesuniec w tab B";
  70.  
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement