|
|
back to boardWhy My program don't work var a:array[1..100,1..100] of byte; counter,i,j,temp,min,n:integer; b:array[1..10000] of integer; begin readln(n); for i:=1 to n do begin for j:=1 to n do read(a[i,j]); writeln; end; {*********************} for i:=1 to n do begin for j:=1 to n do begin counter:=counter+1; b[counter]:=a[i,j]; end; end; for i:=1 to n*n do begin min:=i; for j:=i to n*n do if b[min]>b[j] then min:=j; temp:=b[i]; b[i]:=b[min]; b[min]:=temp; end; writeln; for i:=1 to n*n do write(b[i],' '); end. Re: Why My program don't work Test: 3 1 2 3 4 5 6 7 8 9 Right answer: 1 4 2 7 5 3 8 6 9 Re: Why My program don't work #include "iostream.h" void main() { int n; cin>>n; int a[100][100]; int str=0,st=0,i,j,qst=0,qstr=0; for(i=0;i<n;i++) for(j=0;j<n;j++) cin>>a[i][j]; for(i=0;i<((n*n)+n*2);i++) { if((str>=0)&&(st<n)) {cout<<a[str][st]<<" ";str=str-1;st=st+1;} else { if(st>=n) {str=n-1;st=1+qst;qst++;} if ((str<=0)&&(st<=n)) {st=0;str=1+qstr;qstr++;} } } } Why "Wrong answer" ??? (on test 2) Edited by author 27.04.2006 04:46 |
|
|