|
|
back to boardWhy WA ??!?!!! help me please... type n=record ile:integer; a:array[1..1000]of byte end; var num:n; ile,liczba,i:integer; procedure mnoz(bufor:byte); var w,p,j:integer; begin p := 0; for j:=1 to num.ile do begin w := num.a[j] * bufor + p; num.a[j] := w mod 10; p := w div 10; end; if (p > 0) then begin Inc(j); num.a[j] := p; num.ile := num.ile + 1 end end; begin read(liczba); if liczba>=0 then begin if (liczba>=0)and(liczba<=4)then begin if liczba=4 then writeln('3') else if liczba>=0 then writeln('1') else writeln(liczba); halt end; if (liczba-4)mod 3=0 then begin num.a[1]:=4; num.ile:=1; for i:=1 to (liczba-4)div 3 do mnoz(3) end else if liczba mod 3=0 then begin num.a[1]:=3; num.ile:=1; for i:=1 to (liczba div 3)-1 do mnoz(3) end else if liczba mod 3=1 then begin num.a[1]:=2; num.ile:=1; for i:=1 to (liczba)div 3 do mnoz(3) end else begin num.a[1]:=3; num.ile:=1; for i:=1 to (liczba div 3)-1 do mnoz(3) end; for i:=1 to num.ile do write(num.a[num.ile-i+1]) end end. It's easy /// this my all program on C++ language #include <stdio.h> int N,LRes; long int Res[200]; void Umn3(void) { int i; long int T,P=0; for (i=0;i<LRes;i++) { T=Res[i]; Res[i]=(P+Res[i]*3)%10000; P=(P+T*3)/10000; } if (P>0) { LRes++; Res[i]=P; } } int main(void) { int i; // freopen("input.txt","rt",stdin); // freopen("output.txt","wt",stdout); scanf("%d",&N); if (N==1) { printf("1"); return 0; } LRes=1; /////////there is the main idea of program - ask me if you'll not /////////understand switch (N%3) { case 0: Res[0]=1; N=N/3; break; case 1: Res[0]=4; N=(N-4)/3; break; case 2: Res[0]=2; N=(N-2)/3; break; } for (i=0;i<N;i++) Umn3(); ////////// printf("%ld",Res[LRes-1]); for (i=LRes-2;i>=0;i--) { if (Res[i]/1000==0) printf("0"); if (Res[i]/100==0) printf("0"); if (Res[i]/10==0) printf("0"); printf("%ld",Res[i]); } return 0; } Answer for largest test - check it 1322070819480806636890455259752144365965422032752148167664920368226828 5973467048995407783138506080619639097776968725823559509545821006189118 6534272525795367402762022519832080387801477422896484127439040011758861 8041128947815623094438061566173054086674490506178125480344405547054397 0388958174653682549161362208302685637785822902284163983078878969185564 0408489893760937324217184635993869551676501894058810906042608967143886 4102814350385648747165832010614366132173102768902855220001 Re: Why WA ??!?!!! help me please... > type > n=record > ile:integer; > a:array[1..1000]of byte > end; > > var > num:n; > ile,liczba,i:integer; > > procedure mnoz(bufor:byte); > var > w,p,j:integer; > begin > p := 0; > for j:=1 to num.ile do > begin > w := num.a[j] * bufor + p; > num.a[j] := w mod 10; > p := w div 10; > end; > if (p > 0) then > begin > Inc(j); > num.a[j] := p; > num.ile := num.ile + 1 > end > end; > > begin > read(liczba); > if liczba>=0 then > begin > if (liczba>=0)and(liczba<=4)then > begin > if liczba=4 then writeln('3') > else if liczba>=0 then writeln('1') > else writeln(liczba); > halt > end; > > if (liczba-4)mod 3=0 then (*) > begin > num.a[1]:=4; > num.ile:=1; > for i:=1 to (liczba-4)div 3 do mnoz(3) > end > else if liczba mod 3=0 then > begin > num.a[1]:=3; > num.ile:=1; > for i:=1 to (liczba div 3)-1 do mnoz(3) > end > else if liczba mod 3=1 then <- may be wrong, this condition you already wrote upper (*) (liczba>=4) > begin > num.a[1]:=2; > num.ile:=1; > for i:=1 to (liczba)div 3 do mnoz(3) > end > else > begin > num.a[1]:=3; > num.ile:=1; > for i:=1 to (liczba div 3)-1 do mnoz(3) > end; > > for i:=1 to num.ile do > write(num.a[num.ile-i+1]) > end > end. |
|
|