|
|
вернуться в форумHelp me, please why WA#3 Послано Harry 28 сен 2011 01:25 Here is my code: #include<iostream> #include<algorithm> using namespace std; int main(){ int n,i,a[90],ans[12][12]={0},z,x,y,j; cin>>n; for(i=0; i<n*n; i++)cin>>a[i]; sort(a,a+n*n); z=n*n-1; x=n/2+1; y=x; ans[x][y]=a[z--]; int p=1; while(z>0){ ans[x-p][y]=a[z--]; ans[x+p][y]=a[z--]; ans[x][y-p]=a[z--]; ans[x][y+p]=a[z--]; for(i=y-p; i<=y+p; i++)if(ans[x-p][i]==0)ans[x-p][i]=a[z--]; for(i=y-p; i<=y+p; i++)if(ans[x+p][i]==0)ans[x+p][i]=a[z--]; for(i=x-p; i<=x+p; i++)if(ans[i][y-p]==0)ans[i][y-p]=a[z--]; for(i=x-p; i<=x+p; i++)if(ans[i][y+p]==0)ans[i][y+p]=a[z--]; p++; } for(i=1; i<=n; i++){for(j=1; j<=n; j++)cout<<ans[i][j]<<" "; cout<<endl;} return 0;} |
|
|