SHARE
TWEET

Untitled

a guest May 21st, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program vava;
  2.  
  3. var
  4.   s, is1: string;
  5.   a, b, i, j, n, s1, err, f: integer;
  6.  
  7. begin
  8.   s1 := 0;
  9.   readln(s);
  10.   while (Pos('*', s) <> 0) or (Pos('/', s) <> 0) do
  11.   begin
  12.     i := 1;
  13.     j := 1;
  14.     f := 1;
  15.    // z := 0;
  16.     n := (Pos('*', s));
  17.     if (n = 0) or (n > Pos('/', s)) and (Pos('/', s) <> 0)
  18.     then
  19.     begin
  20.       n := (Pos('/', s));
  21.       f := 0;
  22.     end;
  23.    
  24.    
  25.     while ((n - i) <> 1) and (s[n - i] in ['0'..'9'])  do
  26.       i := i + 1;
  27.      
  28.     if ((n - i) <> 1) then i := i - 1;
  29.      
  30.     if (n-i=2) then //Проверка является ли первым символом минус
  31.       i := i + 1;
  32.      
  33.     if (n-i>2) and (s[n-i-1] = '-') and not (s[n-i-2] in ['0'..'9']) then
  34.        inc(i);
  35.    
  36.     if (s[n+1]='-') then
  37.     begin
  38.  
  39.       inc(j);
  40.      
  41.     end;
  42.    
  43.     while ((n + j) <> length(s)) and (s[n + j] in ['0'..'9'])  do
  44.       j := j + 1;
  45.    
  46.    
  47.     if ((n + j) <> length(s)) then j := j - 1;
  48.    
  49.     Val(copy(s, n - i, i), a, err);
  50.     Val(copy(s, n + 1, j), b, err);
  51.     if(f = 1) then s1 := a * b else s1 := a div b;
  52.     delete(s, n - i, i + 1 + j);
  53.     str(s1, is1);
  54.     insert(is1, s, n - i);
  55.   end;
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.   while (Pos('+', s) <> 0) or (Pos('-', s,2) <> 0) do
  64.   begin
  65.     i := 1;
  66.     j := 1;
  67.     f := 1;
  68.     n := (Pos('+', s));
  69.     if (n = 0) or (n > Pos('-', s,2)) and (Pos('-', s,2) <> 0)
  70.    then
  71.     begin
  72.       n := (Pos('-', s,2));
  73.       f := 0;
  74.     end;
  75.    
  76.    
  77.     while ((n - i) <> 1) and (s[n - i] in ['0'..'9'])  do
  78.       i := i + 1;
  79.      if ((n - i) <> 1) then i := i - 1;
  80.      
  81.      if (n-i=2) then dec(i);
  82.      
  83.     if ((n-i)>2) and (s[n-i-1]='-') and not (s[n-i-2] in ['0'..'9']) then
  84.       dec(i);
  85.    
  86.     if (s[n+1]='-') then
  87.     begin
  88.    
  89.       inc(j);
  90.      
  91.     end;
  92.    
  93.     while ((n + j) <> length(s)) and (s[n + j] in ['0'..'9'])  do
  94.       j := j + 1;
  95.    
  96.    
  97.     if ((n + j) <> length(s)) then j := j - 1;
  98.    
  99.     Val(copy(s, n - i, i), a, err);
  100.     Val(copy(s, n + 1, j), b, err);
  101.     if(f = 1) then s1 := a + b else s1 := a - b;
  102.     delete(s, n - i, i + 1 + j);
  103.     str(s1, is1);
  104.     insert(is1, s, n - i);
  105.    // if ((s[1] = '-') and (Pos('+', s, 2) = 0) and (Pos('-', s , 2) = 0)) then break;
  106.   end;
  107.  
  108.   writeln(s);
  109. end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top