Title Description Description
Xiaoming play a number game, take an n-row N-column number matrix (where n is not more than 100 odd), the number is filled by: in the center of the matrix from 1 to the counterclockwise direction, the circle expands, until n row n column fills the number, output the n row n column square matrix and its diagonal number of the sum.
Enter a description input Description
n (i.e. n rows n columns)
outputs description output Description
N+1 line, n-Behavior matrix, the sum of the last behavior diagonal numbers
sample input to sample
3
Sample output Sample outputs
5 4 3
6 1 2
7 8 9
25
1 varA,c:Array[- -.. -,- -.. -] ofLongint;2 I,j,fx,n,k,num,x,y,tw,ans:longint;3 begin4 READLN (n);5a[0,0]:=1;6k:=1;7num:=2;8x:=0;9y:=0;Tenfx:=0; One whileK<>n Do A begin - if(TWMoD 2=0) and(tw<>0) ThenInc (k); - fori:=1 toK Do the begin - iffx=0 Then - begin - Inc (Y); +a[x,y]:=num; - Inc. (NUM); + End; A iffx=1 Then at begin - Dec (x); -a[x,y]:=num; - Inc. (NUM); - End; - iffx=2 Then in begin - Dec (y); toa[x,y]:=num; + Inc. (NUM); - End; the iffx=3 Then * begin $ Inc (X);Panax Notoginsenga[x,y]:=num; - Inc. (NUM); the End; + End; A Inc (TW); the Inc (FX); +Fx:=fxMoD 4; - End; $ $x:=0; y:=0; - ifNMoD 2<>0 Then - forI:=-nDiv 2 toNDiv 2 Do the begin - Inc (X);Wuyiy:=1; the forJ:=-NDiv 2 toNDiv 2 Do - begin Wuc[x,y]:=A[i,j]; - Inc (Y); About End; $ Writeln; - End; - - ifNMoD 2=0 Then A fori:=2-NDiv 2-2 toNDiv 2-1 Do + begin the Inc (X); -y:=1; $ forJ:=-nDiv 2+1 toNDiv 2 Do the begin thec[x,y]:=A[i,j]; the Inc (Y); the - in End; the Writeln; the End; About fori:=1 toN Do the begin the forj:=1 toN Do the begin +Write (C[i,j],' '); - if(I=J)or(i+j=n) Then the Inc (Ans,c[i,j]);Bayi End; the Writeln; the End; - - writeln (ans); the End.
"CODEVS1160" Serpentine Matrix