input : 15 4 1 2 30 994 50 600 700 999 900 990 991 992 993 40 800 output : 1 50 900 993 2 600 990 40 30 700 991 800 994 999 992 input:: 9 2 1 2 3 4 5 6 7 8 9 output:: 1 6 2 7 3 8 4 9 5 9 4 100 10 1 0 999 2 999 999 1 out: 100 0 999 10 999 999 1 2 1 Edited by author 08.05.2019 13:24 Edited by author 08.05.2019 13:24 WA #2 a = input().split() s = input().split() n, k = int(a[0]), int(a[1]) out = ["" for x in range(n//k+1)] for i in range(k): if i != k - 1: for j in range(n//k+1): if len(s[0]) == 1: out[j] += " " + s[0] s.pop(0) elif len(s[0]) == 2: out[j] += " " + s[0] s.pop(0) else: out[j] += " " + s[0] s.pop(0) else: for j in range(n%k): if len(s[0]) == 1: out[j] += " " + s[0] s.pop(0) elif len(s[0]) == 2: out[j] += " " + s[0] s.pop(0) else: out[j] += " " + s[0] s.pop(0) for i in out: print(i) Edited by author 09.03.2018 19:59 WA 10. Give this test please... Have trouble with this test too... and one question: if input is like that: 7 6 1 2 3 4 5 6 7 should be output like that: 1 3 4 5 6 7 2 or that: 1 3 5 7 2 4 6 The answer is: 1 3 5 7 2 4 6 Remember about the correct number of spaces. My AC program show : 1 3 4 5 6 7 2 it is incorrect answer or test >the columns have the same height with the possible exception of the last column, which may be shorter This test is incorrect. Timus Online Judje Team likes give people incorrect tests. import java.util.Scanner; public class _1506 { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n, k, j, i; n = s.nextInt(); k = s.nextInt(); k = (n + k - 1) / k; int[] a = new int[n]; for (i = 0; i < n; i++) { a[i] = s.nextInt(); } for (j = 0; j < k; System.out.println(""), j++) for (i = j; i < n; i += k) { System.out.print(" " + a[i]); } } } var mas: array [1..100] of integer; mas2: array [1..100, 1..100] of integer; n, k, str, f, i, j, kol: integer; begin readln(n, k); {for i:=1 to n do read mas[i];} {Считаем кол-во строк} if n mod k <> 0 then str := (n div k) + 1 else str := n div k; {Считаем "полную" матрицу} kol := k * str; for i := 1 to n do read(mas[i]); {Заполняем "-1" будущие пустые места} for i := n + 1 to kol do mas[i] := -1; f := 1; for i := 1 to k do for j := 1 to str do begin mas2[j, i] := mas[f]; inc(f); end; for i := 1 to str do begin for j := 1 to k do if mas2[i, j] <> -1 then write(mas2[i, j]:4) else continue; writeln; end; end. Some tests 7 2 1 2 3 4 5 6 7 Answer 1 5 2 6 3 7 4 7 6 1 2 3 4 5 6 7 Answer 1 3 4 5 6 7 2 This answer can't be right. Only the last column may be smaller. Here 5 columns are smaller. OK, second test is not correct, I think now. C++, 0.015 sec, 196 Kb #include <iostream> using namespace std; int main() { int n,k; cin>>n>>k; int m=n/k + ((n%k==0) ? 0:1); int * A=new int [m*k]; for (int i=0;i<n;i++) { cin>>A[i]; } for (int i=n;i<m*k;i++) A[i]=-1; for (int i=0;i<m;i++) { for (int j=0;j<k;j++) { int h=j*m+i; if (A[h]<0) cout<<" "; if (A[h]>-1 && A[h]<10) cout<<" "<<A[h]; if (A[h]>9 && A[h]<100) cout<<" "<<A[h]; if (A[h]>99 && A[h]<1000) cout<<" "<<A[h]; } cout<<endl; } return 0; } Waiting of comments C, 0.015 sec, 112 kb main() { short n,k,a[101],i,j; scanf("%d %d",&n,&k); k=(n+k-1)/k; for(i=0;i<n;i++)scanf("%i",&a[i]); for(j=0;j<k;puts(""),j++) for(i=j;i<n;i+=k) printf("%4d",a[i]); } What's incorrect????? int main() { int n, k; scanf("%d %d", &n, &k); vector<int> mas(100);
mas.assign(100, -1); for (int i=0; i<n; i++) scanf("%d", &mas[i]); int s=n/k; if(n%k!=0) s++; for (int i=0; i<s; i++) { for(int j=0; j<k; j++) if (mas[s*j+i]!=-1) printf("%4d", mas[s*j+i]); printf("\n"); } return 0; } Edited by author 26.04.2011 20:30 vector<int>mas; mas.assign(111,-1); 100 1 1 2 3 4 .. 99 100 ans: 1 2 3 4 .. 99 100 Edited by author 09.07.2011 17:54 My AC code : ans: 1 2 3 4 . . . 99 100 This my code: var a:array[1..100,0..100] of integer; i,n,k,ki,kj,j,kn:integer; begin readln(n,k); kn:=k; k:=n div k+1; if kn=n then k:=1; ki:=1; kj:=1; for i:=1 to n do begin read(j); a[ki,kj]:=j; inc(a[ki,0]); inc(ki); if ki>k then begin ki:=1; inc(kj); end; end; for i:=1 to k do begin for j:=1 to a[i,0] do write(a[i,j]:4); writeln; end; end. plz help me! Edited by author 31.03.2008 03:19 9 3 1 2 3 4 5 6 7 8 9 => 1 4 7 2 5 8 3 6 9 I get WA#1 here is my code #include <cstdlib> #include <iostream> using namespace std; int i, j, n, k, say, a[101]; int main(int argc, char *argv[]) { cin >> n >> k;
for( i = 0; i < n ; i++ ) cin >> a[ i ]; if( n%k != 0) say = n/k + 1; else say = n/k;
for( j = 0; j < say; j++ ){ cout << a[ j ]; i = j + say; while( i < n){
cout <<" "<< a[ i ]; i += say; } if( j < say-1 ) cout << endl; }
return 0; } Output: The width of each column must be 4 symbols; the numbers must be aligned to the right edge and padded with spaces to the required width hi.you have 3 error's 1.you get 1 test case,but question has t test case. you can add while(cin>>n>>k){...} to het t,test case,t>0; 2.you end of ant test case add cout<<endl; 3.to any answer printf(" %3d",a[i]); good luck. 9=n 3=k 1 4 7 1 5 9 2 5 8 2 6 3 6 9 or 3 7 4 8 The task says: 'their<columns'> height would be minimal'. So the right one is correct. which answer? n=11,k=5, '1 2 3 4 5 6 7 8 9 10 11'; 1 4 7 10 ? 2 5 8 11 ? 3 6 9 ? ? or 1 4 6 8 10 2 5 7 9 11 3 ? ? ? which answer? n=11,k=5, '1 2 3 4 5 6 7 8 9 10 11'; 1 4 7 10 ? 2 5 8 11 ? 3 6 9 ? ? or 1 4 6 8 10 2 5 7 9 11 3 ? ? ? Read task. >>It is guaranteed that solution is always >>which answer? >>n=11,k=5, '1 2 3 4 5 6 7 8 9 10 11'; >>1 4 7 10 ? >>2 5 8 11 ? >>3 6 9 ? ? >>or >>1 4 6 8 10 >>2 5 7 9 11 >>3 ? ? ? My AC program show : 1 3 5 7 9 11 2 4 6 8 10 Edited by author 11.03.2009 15:58 My AC Program right: 11 5 1 2 3 4 5 6 7 8 9 10 11 answer: 1 4 7 10 2 5 8 11 3 6 9 #include <stdio.h> int x[101]; void main() { int n=0,m=0,i=0,j=0,k=0; scanf("%d", &n); scanf("%d", &m); i=0; for (i=0;i<n;i++) scanf("%d", &x[i]); i=0; m=2; while ((i<n)&&(k<n)) { j=i; while (j<n) { printf("%4.d",x[j]); j=j+m; k++; } printf("\n"); i++; }
} 4 3 1 2 30 40 For this input there is no solution!! No way exists for 4 numbers to be placed into 3 columns, when 2 columns has equal length and 3rd has littler length! (but this input doesn't permitted by the statement of the task o_O) И что с этим делать? Я опять запутался >_< Edited by author 20.10.2009 21:41 Read the statement more carefully. It is guaranteed that solution is always exist. I sumbit this codes and Got WA#1. WriteLn('1 40 700'); WriteLn('2 50'); WriteLn('30 600'); WriteLn('1 40 700'); WriteLn('2 50'); WriteLn('30 600'); WriteLn('1 40 700'); WriteLn('2 50'); WriteLn('30 600'); all Get WA#1. How I write output? "-" = " " "---1--40-700" "---2--50" "---30-600" Edited by author 29.10.2006 14:51 WriteLn(1:4, 40:4, 700:4); WriteLn(2:4, 50:4); WriteLn(30:4, 600:4); Sample output in problem statement wil be corrected soon. Isn't it more precisely: ---1--40-700 ---2--50 --30-600 where "-"==" " What can I do in C++ to output as in Pascal without hand-calculating the numbers of blanks? program t1506; var n,m,a,b,c,i,j,l:integer; k,o:real;s:string; h:array [1..100] of integer; q:array [1..10,1..10] of integer; p:array [1..10,1..10] of integer; begin readln(n,k); for i:=1 to n do read(h[i]); m:=trunc(sqrt(n)); if frac(sqrt(n))<>0 then inc(m); for i:=1 to m do for j:=1 to m do begin inc(b); p[i,j]:=h[b]; str(h[b],s); q[i,j]:=length(s); if q[i,j]>a then a:=q[i,j]; end; for i:=1 to m do for j:=1 to m do begin write(' '); for b:=1 to (a-q[j,i]) do write(' '); if j<>m then begin write(p[j,i]); inc(l); end else begin writeln(p[j,i]); inc(l); end; if l=n then halt; end; end. Edited by author 03.03.2010 10:22 Is this Test correct? 4 3 1 2 3 4 >> 1 3 2 4 my AC prog. gives me that answer because 1 2 3 ___4 isn't correct 100%. {same test 16 5} Edited by author 09.04.2008 23:39 There are some numbers n and k, that there is not any correct solution. Probably your case is one of them. P.S. See my post. My AC program show : 1 3 4 2 |
|