Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- #include <fstream>
- #include <iomanip>
- using namespace std;
- const int m=3,n=3;
- int licznik_przesuniec=0;
- void wypelnianie(int tab[m][n]){
- for(int i=0;i<m;i++){
- for(int j=0;j<n;j++){
- tab[i][j]=-100+rand()%201;
- }
- }
- };
- void przesuwanie(int tab[m][n]){
- int suma=0,temp;
- for(int i=0;i<m;i++){
- for(int j=0;j<n;j++)
- suma=suma+tab[i][j];
- if(suma>0){
- temp=tab[i][n-1];
- for(int b=n-1;b>=0;b--){
- tab[i][b]=tab[i][b-1];
- }
- tab[i][0]=temp;
- licznik_przesuniec++;
- }
- suma=0;
- }
- }
- void zapis(int tab[m][n], string s){
- ofstream plik;
- plik.open(s.c_str(), ios::app);
- if(plik.good()){
- for(int i=0;i<m;i++){
- for(int j=0;j<n;j++){
- plik<<tab[i][j]<<" ";
- }
- cout<<endl;
- }
- plik<<tab[m][n];
- }
- }
- int main() {
- int A[m][n], B[m][n];
- int tempA,tempB;
- string s="tab_A.txt", s1="tab_B.txt";
- srand(time(0));
- wypelnianie(A);
- wypelnianie(B);
- przesuwanie(A);
- licznik_przesuniec=tempA;
- licznik_przesuniec=0;
- przesuwanie(B);
- licznik_przesuniec=tempB;
- zapis(A,s);
- zapis(B,s1);
- if(tempA>tempB)
- cout<<"wiecej przesuniec w tab A";
- else
- cout<<"wiecej przesuniec w tab B";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement