ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1149. Sinus Dances

it accepted!
Posted by Jumbo 22 Mar 2011 01:45
var n1,n,i:integer; a:array[1..200] of string;  s,s1:string;
procedure zap(x:integer);
var i,k:integer; s,s1,s2,s3:string;
begin
a[1]:='sin(1)';
for i:=2 to x do begin

 s:=a[i-1];

 for k:=length(s) downto 1 do
  if (s[k]>='0') and (s[k]<='9') then begin
  str(i-1,s3);  delete(s,k+1-length(s3),length(s3));break end;


  if i mod 2=0 then begin
   str(i-1,s1);
   str(i,s2);
   s1:=s1+'-'+'sin'+'('+s2+')';
   insert(s1,s,k+1-length(s3));

  end else begin
    str(i-1,s1);
   str(i,s2);
   s1:=s1+'+'+'sin'+'('+s2+')';
   insert(s1,s,k+1-length(s3));
  end;
  a[i]:=s;
 end;
end;
begin
read(n);
zap(n);
n1:=n-1;
str(n,s1);
s:='('+a[1]+'+'+s1+')';

for i:=2 to n-1 do begin
 str(n1,s1);
 s:='('+s+a[i]+'+'+s1+')';
 n1:=n1-1;

end;

s:=s+a[n]+'+'+'1';
if n=1 then writeln(a[1]+'+'+'1') else writeln(s);


end.