P1103 - 多项式输出From lx11111 Normal (OI)总时限:10s 内存限制:128MB 代码长度限制:64KB | |||||||
---|---|---|---|---|---|---|---|
|
noip2009普及组第一题。
1 program p1103; 2 3 var n,i:integer; 4 5 st,s1,s2:ansistring; 6 7 a:array[0..10000]of integer; 8 9 flag:boolean; 10 11 procedure init; 12 13 begin 14 15 flag:=true; 16 17 readln(n);st:=‘‘; 18 19 for i:=n+1 downto 1 do 20 21 begin 22 23 read(a[i]); 24 25 if (a[i]<>0)and flag then flag:=false; 26 27 end; 28 29 if flag then begin write(‘0‘);halt;end; 30 31 end; 32 33 begin 34 35 init; 36 37 for i:=n+1 downto 2 do 38 39 begin 40 41 if a[i]=0 then begin dec(n);continue;end; 42 43 if a[n+1]<0 then st:=st+‘-‘; 44 45 if i<>n+1 46 47 then if a[i]<0 48 49 then st:=st+‘-‘ 50 51 else if a[i]>0 52 53 then st:=st+‘+‘; 54 55 a[i]:=abs(a[i]); 56 57 if (a[i]<>1) 58 59 then begin 60 61 str(a[i],s1); 62 63 st:=st+s1; 64 65 end; 66 67 str(i-1,s2); 68 69 st:=st+‘x‘; 70 71 if i-1>1 then 72 73 begin 74 75 st:=st+‘^‘; 76 77 st:=st+s2; 78 79 end; 80 81 end; 82 83 if a[1]<>0 then 84 85 begin 86 87 if (a[1]>0)and(st<>‘‘) then st:=st+‘+‘; 88 89 str(a[1],s1); 90 91 st:=st+s1; 92 93 end; 94 95 writeln(st); 96 97 readln; 98 99 readln; 100 101 end.
原文:http://www.cnblogs.com/111qqz/p/4296129.html