Advertisement
Guest User

task8

a guest
Apr 19th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.03 KB | None | 0 0
  1. var s,s1,s2:string;
  2.     i,k,k1,k2,n1,n2,t,a,b:integer;
  3.     z:char;
  4. Begin
  5.   a:=0;
  6.   b:=0;
  7.  
  8.   readln(s);
  9.  
  10.   k:=pos('*',s);
  11.  
  12.   while k<>0 do begin
  13.  
  14.     k1:=k-1;
  15.     k2:=k+1;
  16.    
  17.     while (s[k1]<>'+') and (s[k1]<>'-') and (s[k1]<>'*') and (k1<>1) do begin
  18.       k1:=k1-1;
  19.     end;
  20.    
  21.     if k1<>1 then k1:=k1+1;
  22.  
  23.     while (s[k2]<>'+') and (s[k2]<>'-') and (s[k2]<>'*') and (k2<>length(s)) do k2:=k2+1;
  24.    
  25.     if k2<>length(s) then k2:=k2-1;
  26.  
  27.     s1:=copy(s,k1,k-k1);
  28.     s2:=copy(s,k+1,k2-k);
  29.    
  30.     val(s1,n1,t);
  31.     val(s2,n2,t);
  32.    
  33.     n1:=n1*n2;
  34.    
  35.     str(n1,s1);
  36.    
  37.     delete(s,k1,k2-k1+1);
  38.    
  39.     insert(s1,s,k1);
  40.    
  41.    
  42.     k:=pos('*',s);
  43.   end;
  44.  
  45.   z:='+';
  46.  
  47.   for i:=1 to length(s) do begin
  48.     case s[i] of
  49.       '0'..'9': a:=a*10+ord(s[i])-ord('0')
  50.       else begin
  51.         if z='+'
  52.          then b:=b+a
  53.          else b:=b-a;
  54.         z:=s[i];
  55.         a:=0;
  56.       end;
  57.     end;
  58.   end;  
  59.  
  60.   if z='+' then b:=b+a
  61.     else b:=b-a;
  62.    
  63.   writeln(b);
  64.  
  65. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement