don't round up. or you will get wa8. Edited by author 28.05.2023 19:05 Guess, why I had wasted 18 attempts? The exponent can have + sign: 1.3e+32 All bad wished to author. I was trying C++ for several hours. Can't defeat test case No. 7. So, I gave up and got AC using Python Decimal module just after several minutes I stopped trying C++. It is bad I think that I don't solved with C++. Literally no idea why WA#7. I tried rounding and truncation. The result was always the same. This is my programm below: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Globalization; namespace _1248 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); double s = 0; for (int i = 0; i < n; i++) { string strS = Console.ReadLine(); double ch =0; if (strS.Contains("e")) { string[] arr = strS.Split('e'); double ss = double.Parse (arr[1]); ch = double.Parse(arr[0], CultureInfo.InvariantCulture) * Math.Pow(10, ss); } else ch = double.Parse (strS ); s +=ch; } StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0:0.000000000000000000e0}", s); string sss = sb.ToString(); sss = sss.Replace(',', '.'); //sss = sss.Replace("e0", ""); Console.WriteLine(sss); } } } I tried everything before I realized that my program should accept numbers like 1.e+1 even if there is no digits after '.'. Weird! I hope this information would be helpful to someone. Почему моя программа выдаёт неправельный ответ на 6 вопрос? Looks like there is some bug in it =))) program p1; type tabel=array[-100..100] of byte; var r,eror,s,a,c,i,num,b:integer; n,pr:string; x:tabel; procedure insertare(var t:tabel; f:string; p:integer); var q,e,i:integer; begin for i:=1 to length(f) do begin s:=0; val(f[length(f)-i+1],q,e); if t[i+p-1]+q+s<=9 then begin t[i+p-1]:=t[-1+i+p]+q+s; s:=0; end else begin t[i+p-1]:=t[i+p-1]+q+s-10; s:=1; end; end; while s<>0 do begin inc(i); if t[i+p-1]+s<=9 then begin t[i+p-1]:=t[i+p-1]+s; s:=0; end else begin t[i+p-1]:=t[i+p-1]+s-10; s:=1; end; end; end; begin s:=0; for i:=-100 to 100 do x[i]:=0; readln(num); for i:=1 to num do begin readln(n); a:=pos('e',n); val(copy(n,pos('e',n)+1,length(n)),b,eror); if pos('.',n)<>0 then begin pr:=copy(n,1,pos('.',n)-1); insertare(x,pr,b); pr:=copy(n,pos('.',n)+1,a-pos('.',n)-1); insertare(x,pr,b-(a-pos('.',n)-1)); end else begin pr:=copy(n,1,pos('e',n)-1); insertare(x,pr,b); end; end; for i:=100 downto -100 do if x[i]<>0 then if x[i-20]>5 then insertare(x,'1',i-19); for i:=100 downto -100 do if x[i]<>0 then begin write(x[i],'.'); for c:=i-1 downto i-19 do write(x[c]); write('e'); if i<>0 then write(i); break; end; readln; end. Why, test please and tell me why it don't work 8 9.23e4 1.23e0 12.2e3 13.233e1 12.2e-3 9.2e-1 10.22e-3 123.12e-1 92300 1.23 12200 132.33 0.0122 0.92 0.01022 12.312 ---------------------- + 104646.81442 Result: 1.046468144200000000e5 Remember the "." doesn't have to be eg. 9e0 9e2 9e-2 Also you don't have to round your result! i have AC Edited by author 19.04.2011 20:29 Edited by author 19.04.2011 20:31 'e' must be! Thanks for the test but it has a litle wrong format: There should be exactly one non-zero digit before the point. just ACed.... spent two hours debugging. very nice problem! Edited by author 02.12.2011 05:00 If you get wrong answer on test #6,you should notice that there may be a '+' following the 'e'. oh!, thanks... it's give my chance to look at my self... what the bullshit is it! when the answer is 0, what's the output? Edited by author 19.11.2010 20:00 The answer can't be equal 0, because all numbers are positive. Because I got AC without any trunc or round! Edited by author 15.11.2010 17:38 Edited by author 09.11.2010 00:31 Checker accepts any number of digits in mantissa, so it is possible to output just exact answer having all digits. Rounding to 19 digits or appending zeros to 19 digits is not required. For answer calculated in java.math.BigDecimal the following simple statement works: out.println(sum.toPlainString() + "e0"); {$N+} program a1; var i,j,n,pl:word; s,sum:Extended; res:string; fl,fl2:boolean; begin read(n); read(s); sum:=s; for i:=1 to n-1 do begin read(s); sum:=sum+s; end; str(sum,res); n:=length(res); fl:=false; fl2:=true; for i:=1 to n do begin if res[i]='E' then begin res[i]:='e'; pl:=i; fl:=true; end; if (fl=true){ and (fl2=true)} and (res[pl+1]='0') or (res[i]='+') then begin i:=i-1; fl2:=false; for j:=pl+1 to n do begin res[j]:=res[j+1]; if res[j]<>'0' then fl2:=false; end; end; end; for i:=1 to length(res)-1 do res[i]:=res[i+1]; write(res); end. Because of you try to change variable i , used for cycle For Please give me test 6. Thanks Help me, PLEASE!!!!!!!!!!!!!!!!!!!!! If in answer in mantissa 21-th digit >=5 you must do: mantissa = mantissa + 0.000000000001 (easier speaking, you must round your answer :) ). Read forum!!! var a,b:array[-250..250] of byte; x1,x,i,j,n,code:integer; s:string; procedure E; var i,ymn,t:integer; minus:boolean; begin minus:=false; ymn:=0; t:=0; for i:=1 to length(s) do if (s[i]='e') or (s[i]='E') then begin t:=i+1; val(copy(s,t,length(s)-t+1),ymn,code); delete(s,i,length(s)-i+1); break; end; t:=0; for i:=1 to length(s) do if s[i]='.' then t:=i-1; if t<>0 then delete(s,t+1,1); if t=0 then t:=length(s); ymn:=ymn+t; if ymn<=0 then begin for i:=1 to abs(ymn) do s:='0'+s; s:='.'+s; s:='0'+s; end else begin if ymn<length(s) then insert('.',s,ymn+1) else begin ymn:=ymn-length(s); for i:=1 to ymn do s:=s+'0'; end; end; end; begin { assign(input,'c:\test.txt'); reset(input);} readln(n); for i:=1 to n do begin fillchar(b,sizeof(b),0); readln(s); if pos('.',s)=0 then if pos('e',s)=0 then s:=s+'.0' else insert('.0',s,pos('e',s)); E; if pos('.',s)=0 then s:=s+'.0'; for j:=pos('.',s)-1 downto 1 do begin val(s[j],x,code); b[j-pos('.',s)]:=x; end; for j:=pos('.',s)+1 to length(s) do begin val(s[j],x,code); b[j-pos('.',s)]:=x; end; x:=0; for j:=200 downto 1 do begin x1:=x; x:=(b[j]+a[j]+x1) div 10; a[j]:=(a[j]+b[j]+x1) mod 10; end; for j:=-1 downto -200 do begin x1:=x; x:=(b[j]+a[j]+x1) div 10; a[j]:=(a[j]+b[j]+x1) mod 10; end; end; { for i:=-10 to 10 do write(a[i]);} x:=0; for i:=-200 to 0 do if a[i]<>0 then break; if i<>0 then begin write(a[i],'.'); x:=i+1; j:=0; for i:=x to 200 do if i<>0 then begin inc(j); if j=19 then break else write(a[i]); end; write('e',abs(x)); end else begin j:=0; for i:=1 to 200 do if a[i]<>0 then break; x:=-(i); if i=200 then x:=0; write(a[i],'.'); for i:=abs(x)+1 to 250 do begin inc(j); if j=19 then break else write(a[i]); end; write('e',x); end; end. I think you must round answer!!! You must be more attentively. Read forum!!! Test special for your programm: 3 1.999999999999999999e-11 0.080000000000000000e-9 0.000000000000000009e-12 My Ac programm answer: 1.000000000000000000e-10 I hope this test will help you!!! I've got AC using long number arithmetics. Somebody solve this problem without the use of long arithmetic? 21 9e0 9e1 9e2 9e3 9e4 9e5 9e6 9e7 9e8 9e9 9e10 9e11 9e12 9e13 9e14 9e15 9e16 9e17 9e18 9e19 9e20 Correct answer is 1.000000000000000000e21 My AC program outputs 9.9999999999999999999e20 This answer is also correct. Your program have not to round answer. From my experience, I think it is necessary to round the answer. Yes, you are right. The ans must get rounding |
|