const
MAX = 20;
var
s:string;
stack:array[1..MAX] of string;
top:integer;
i:byte;
procedure Push(ch:string);
begin
if top>=MAX then WriteLn('Stask full')
else
begin
stack[top]:=ch;
top:=top+1;
end;
end;
function Pop:string;
begin
top:=top-1;
if top<1 then
begin
WriteLn('Stack underflow');
top:=top+1;
end
else Pop := stack[top];
end;
begin
top:=1;
s:='<asdf<asdf>asdf>';//правильная строка
for i:=1 to length(s) do
begin
if s[i]='<' then Push('<');
if s[i]='>' then
if Pop()<>'<' then WriteLn('Ошибка!');
end;
if top<>1 then WriteLn('Ошибка!');
top:=1;
s:='<asdf<asdfasdf>';//не правильная строка
for i:=1 to length(s) do
begin
if s[i]='<' then Push('<');
if s[i]='>' then
if Pop()<>'<' then WriteLn('Ошибка!');
end;
if top<>1 then WriteLn('Ошибка!');
end.
Объяснение:
Вот простой пример написанный на С++
Если нужно объяснить программу то пиши: Telegram @danileremeev
#include <iostream>
using namespace std;
struct st{
int x1, x2, x3, amount, composition, sum_of_squares;
int number, thousand, hundreds, dozens, units;
int a, b, amount_ab, difference_ab, composition_ab;
}; st St;
int main() {
setlocale(0, "");
cout << "1)\n";
cout << "x1: "; cin >> St.x1;
cout << "x2: "; cin >> St.x2;
cout << "x2: "; cin >> St.x3;
St.amount = St.x1 + St.x2 + St.x3;
St.composition = St.x1 * St.x2 * St.x3;
St.sum_of_squares = (St.x1 * St.x1) + (St.x2 * St.x2) + (St.x3 * St.x3);
cout << "суммa: " << St.amount << "\nпроизведение: " << St.composition << "\nсумму квадратов: "<<St.sum_of_squares << endl;
cout << "\n2)\n";
for (;;) {
cout << "введите четырехразрядное число: ";
cin >> St.number;
if (St.number >= 1000 && St.number <= 9999) {
St.thousand = St.number / 1000;
St.hundreds = St.number / 100;
St.dozens = St.number / 10;
St.units = St.number / 1;
cout << "Тысяч - " << St.thousand << ", сотен - " << St.hundreds << ", десятков - " << St.dozens << ", единиц - " << St.units;
break;
}
}
cout << "\n\n3)\n";
for (;;) {
cout << "Введите два натуральных числа <=10\n";
cin >> St.a >> St.b;
if (St.a >= 0 && St.a <= 10 && St.b >= 0 && St.b <= 10) {
St.amount_ab = St.a + St.b;
St.difference_ab = St.a - St.b;
St.composition_ab = St.a * St.b;
cout << "суммa: " << St.amount_ab << "\nразность: " << St.difference_ab <<"\nпроизведение: " << St.composition_ab << endl;
break;
}
}
system("pause > nul");
}