| Код | #pragma hdrstop #include <stdio.h> #include <conio.h> #include <iostream> #include <iomanip>
int change(int *a,int *b) { int i=*a; *a=*b; *b=i; } #pragma argsused using namespace std; int main(int argc,char* argv[]) { int j,n,m,s1=0,s2=0,x,g=0; int mas[n][n]; cin>>n; m=n*n-n;
for(j;j<n;j++) for(x;x<n;x++) { mas[j][x]=rand()%3-0;
if(mas[j][x]==0) g++; if(g==m) mas[j][x]=rand()%2+1;
if(mas[j][x]==1) s1++; if(mas[j][x]==2) s2++; } for(j;j<n;j++) { for(x;x<n;x++) { if(mas[j][x]==1) cout<<"b"<<" ";
if(mas[j][x]==2) cout<<"s"<<" ";
if(mas[j][x]==0) cout<<" "<<" ";
cout<<endl; } } int s3=0,s4=0,z,v; while(!(z==s1)) { for(j;j<n;j++) for(x;x<n;x++) {if(mas[j][x]==1) s3++; } z++; } while(!(v==s2)) { for(j;j<n;j++) for(x;x<n;x++) { if(mas[j][x]==2) s4++; } v++; } while((s3==s1)&&(s4==s2)) { for(j;j<n;j++) for(x;x<n;x++) { if((mas[j][x]==1)&&(mas[j+1][x]==0)) change(&mas[j][x],&mas[j+1][x]);
if((mas[j][x]==1)&&(!(mas[j+1][x]==0))&&(mas[j][x+1]==0)) change(&mas[j][x],&mas[j][x+1]);
if((mas[j][x]==1)&&(!(mas[j+1][x]==0))&&(mas[j][x-1]==0)) change(&mas[j][x],&mas[j][x-1]); }
for(j;j<n;j++) for(x;x<n;x++) { if((mas[j][x]==2)&&(mas[j-1][x]==0)) change(&mas[j][x],&mas[j-1][x]);
if((mas[j][x]==2)&&(!(mas[j+1][x]==0))&&(mas[j][x+1]==0)) change(&mas[j][x],&mas[j][x+1]);
if((mas[j][x]==2)&&(!(mas[j+1][x]==0))&&(mas[j][x-1]==0)) change(&mas[j][x],&mas[j][x-1]); }
} for(j;j<n;j++) { for(x;x<n;x++) { if(mas[j][x]==1) cout<<"b"<<" ";
if(mas[j][x]==2) cout<<"s"<<" ";
if(mas[j][x]==0) cout<<" "<<" ";
cout<<endl; } } }
|
Добавлено через 59 секунд посмотрите чего не так в коде |