Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program vava;
- var
- s, is1: string;
- a, b, i, j, n, s1, err, f: integer;
- begin
- s1 := 0;
- readln(s);
- while (Pos('*', s) <> 0) or (Pos('/', s) <> 0) do
- begin
- i := 1;
- j := 1;
- f := 1;
- // z := 0;
- n := (Pos('*', s));
- if (n = 0) or (n > Pos('/', s)) and (Pos('/', s) <> 0)
- then
- begin
- n := (Pos('/', s));
- f := 0;
- end;
- while ((n - i) <> 1) and (s[n - i] in ['0'..'9']) do
- i := i + 1;
- if ((n - i) <> 1) then i := i - 1;
- if (n-i=2) then //Проверка является ли первым символом минус
- i := i + 1;
- if (n-i>2) and (s[n-i-1] = '-') and not (s[n-i-2] in ['0'..'9']) then
- inc(i);
- if (s[n+1]='-') then
- begin
- inc(j);
- end;
- while ((n + j) <> length(s)) and (s[n + j] in ['0'..'9']) do
- j := j + 1;
- if ((n + j) <> length(s)) then j := j - 1;
- Val(copy(s, n - i, i), a, err);
- Val(copy(s, n + 1, j), b, err);
- if(f = 1) then s1 := a * b else s1 := a div b;
- delete(s, n - i, i + 1 + j);
- str(s1, is1);
- insert(is1, s, n - i);
- end;
- while (Pos('+', s) <> 0) or (Pos('-', s,2) <> 0) do
- begin
- i := 1;
- j := 1;
- f := 1;
- n := (Pos('+', s));
- if (n = 0) or (n > Pos('-', s,2)) and (Pos('-', s,2) <> 0)
- then
- begin
- n := (Pos('-', s,2));
- f := 0;
- end;
- while ((n - i) <> 1) and (s[n - i] in ['0'..'9']) do
- i := i + 1;
- if ((n - i) <> 1) then i := i - 1;
- if (n-i=2) then dec(i);
- if ((n-i)>2) and (s[n-i-1]='-') and not (s[n-i-2] in ['0'..'9']) then
- dec(i);
- if (s[n+1]='-') then
- begin
- inc(j);
- end;
- while ((n + j) <> length(s)) and (s[n + j] in ['0'..'9']) do
- j := j + 1;
- if ((n + j) <> length(s)) then j := j - 1;
- Val(copy(s, n - i, i), a, err);
- Val(copy(s, n + 1, j), b, err);
- if(f = 1) then s1 := a + b else s1 := a - b;
- delete(s, n - i, i + 1 + j);
- str(s1, is1);
- insert(is1, s, n - i);
- // if ((s[1] = '-') and (Pos('+', s, 2) = 0) and (Pos('-', s , 2) = 0)) then break;
- end;
- writeln(s);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement