var
s, s1, s2, s3, s4, tmp1, tmp2: string;
i, a, b, c, d, e, f: integer;
begin
Writeln('Введите строку: ');
Readln(s);
//
for var k := 1 to length(s) do
begin
if (s[k] = '(') then
begin
var j := k + 1;
while (s[j].IsDigit) do
begin
tmp1 := tmp1 + s[j];
j := j + 1;
end;
var ch := s[j];
j := j + 1;
while (s[j].IsDigit) do
begin
tmp2 := tmp2 + s[j];
j := j + 1;
end;
case ch of
'+': begin s := s.Remove(k - 1, j - k + 1); s := s.Insert(k - 1, inttostr(tmp1.ToInteger + tmp2.ToInteger)); end;
'-': begin s := s.Remove(k - 1, j - k + 1); s := s.Insert(k - 1, inttostr(tmp1.ToInteger - tmp2.ToInteger)); end;
'*': begin s := s.Remove(k - 1, j - k + 1); s := s.Insert(k - 1, inttostr(tmp1.ToInteger * tmp2.ToInteger)); end;
'/': begin s := s.Remove(k - 1, j - k + 1); s := s.Insert(k - 1, inttostr(tmp1.ToInteger div tmp2.ToInteger)); end;
end;
break;
end;
end;
//
for i := 1 to length(s) do
begin
if (s[i] = '+') or (s[i] = '-') or (s[i] = '*') or (s[i] = '/') then
begin
s1 := copy(s, 1, i - 1);
s2 := copy(s, i + 1, length(s));
c := i;
end;
end;
for i := 1 to length(s1) do
begin
if (s1[i] = '+') or (s1[i] = '-') or (s1[i] = '*') or (s1[i] = '/') then
begin
s3 := copy(s1, 1, i - 1);
s4 := copy(s1, i + 1, length(s1));
e := i;
end;
end;
Val(s3, a, d);
Val(s4, b, d);
Val(s2, f, d);
if (s[e] = '/') and (s[c] = '/') then Writeln((a div b) div f);
if (s[e] = '/') and (s[c] = '*') then Writeln((a div b) * f);
if (s[e] = '+') and (s[c] = '*') then Writeln(a + (b * f));
if (s[e] = '*') and (s[c] = '*') then Writeln(a * b * f);
if (s[e] = '+') and (s[c] = '/') then Writeln(a + (b div f));
if (s[e] = '*') and (s[c] = '+') then Writeln((a * b) + f);
if (s[e] = '/') and (s[c] = '+') then Writeln((a div b) + f);
if (s[e] = '*') and (s[c] = '/') then Writeln((a * b) div f);
if (s[e] = '+') and (s[c] = '+') then Writeln(a + b + f);
if (s[e] = '-') and (s[c] = '-') then Writeln(a - b - f);
if (s[e] = '+') and (s[c] = '-') then Writeln(a + b - f);
if (s[e] = '-') and (s[c] = '+') then Writeln(a - b + f);
if (s[e] = '*') and (s[c] = '-') then Writeln((a * b) - f);
if (s[e] = '/') and (s[c] = '-') then Writeln((a div b) - f);
if (s[e] = '-') and (s[c] = '*') then Writeln(a - (b * f));
if (s[e] = '-') and (s[c] = '/') then Writeln(a - (b div f));
end.
bd = {} #База данных будет организована в виде словаря
while 1:
name = input("Введите имя пассажира: ") #Имя - ключ к весу и количеству вещей
kol_vo = int(input("Введите кол-во вещей: ")) #Не требует объяснения
ves = float(input("Введите вес багажа: "))
bd[name]={'kol-vo':kol_vo, 'ves':ves} #По имени получаем дальнейшую информацию
srednee=0 #Сбрасываем среднее арифметическое
for passazir in bd: #Переберём пассажиров
srednee+=bd[passazir]['kol-vo'] #Сложим кол-во их вещей
srednee/=len(bd) #И разделим на кол-во пассажиров
for passazir in bd: #Переберём пассажиров
if bd[passazir]['kol-vo'] > srednee: #Если у пассажира больше среднего
print("У пассажира %s вещей больше среднего!" % passazir) #Песатаем его имя
if input("Завершить [y/n]? ").lower() == 'y': #Проверяем, выйти ли из цикла
break
#.lower() - переводит строку в нижний регистр
#" text %s text" % переменная - подставляет переменную в текст ( аналогично " text " + переменная + " text")
Объяснение:
На языке Pascal с описанной функцией в объяснении:
Объяснение:
var
a, b, c: integer;
function f(a: integer; b: integer): integer;
begin
c:=a+b;
f:=3*c*sqr(c)+275*sqr(b)-127*a-41
end;
begin
readln(a);
readln(b);
writeln(f(a,b))
end.
Проверил значениями а=2, b=3, на калькуляторе 2555, программа выдает 2555. Функция sqr возводит число в квадрат.