int main() { std::string str; getline(std::cin,str);
const int n = 5; std::string c[n] = { "=", "==", "!=", "a +=", "a -=" }; std::string psl[n] = { ": =", "=", "#", "a = a +", "a = a -" };
for (unsigned int i = n-1; i > 0; i--){ int p = str.find(c[i]); while (p > 0) { str.replace(p, c[i].size(), psl[i]); p = str.find(c[i]); } } std::cout << str; return 0; }
// PascalABC.NET 3.1, сборка 1230 от 27.04.2016 var a:array[1..10] of integer; i,s:integer; begin Randomize; s:=0; for i:=1 to 10 do begin a[i]:=Random(11)+10; Write(a[i],' '); s:=s+a[i]*sqr(a[i]) end; Writeln; Writeln('Сумма кубов ',s); for i:=1 to 10 do begin a[i]:=a[i]-5; Write(a[i],' ') end; Writeln end.
#include <string>
int main()
{
std::string str;
getline(std::cin,str);
const int n = 5;
std::string c[n] = { "=", "==", "!=", "a +=", "a -=" };
std::string psl[n] = { ": =", "=", "#", "a = a +", "a = a -" };
for (unsigned int i = n-1; i > 0; i--){
int p = str.find(c[i]);
while (p > 0)
{
str.replace(p, c[i].size(), psl[i]);
p = str.find(c[i]);
}
}
std::cout << str;
return 0;
}
// PascalABC.NET 3.1, сборка 1230 от 27.04.2016
begin
var a:=ArrRandom(10,10,20); a.Println;
Writeln('Сумма кубов ',a.Select(x->x*x*x).Sum);
a.Transform(x->x-5); a.Println
end.
Тестовое решение
14 17 12 17 20 11 13 18 19 20
Сумма кубов 46517
9 12 7 12 15 6 8 13 14 15
2. "Школьный вариант"
// PascalABC.NET 3.1, сборка 1230 от 27.04.2016
var
a:array[1..10] of integer;
i,s:integer;
begin
Randomize;
s:=0;
for i:=1 to 10 do begin
a[i]:=Random(11)+10;
Write(a[i],' ');
s:=s+a[i]*sqr(a[i])
end;
Writeln;
Writeln('Сумма кубов ',s);
for i:=1 to 10 do begin
a[i]:=a[i]-5;
Write(a[i],' ')
end;
Writeln
end.