Var s:string; n,k,i:integer; begin for n:=1 to 2 do begin writeln('Введите строку ',n,':'); readln(s); k:=0; for i:=1 to length(s) do begin case s[i] of '[': k:=k+1; ']': k:=k-1; end; end; if k=0 then writeln('В строке ',s,' количество [ и ] одинаково') else writeln('В строке ',s,' количество [ и ] не одинаково'); end; end.
Пример: Введите строку 1: c:=a[imax,j]; a[imax,j]:=a[imin,j]; a[imin,j]:=c В строке c:=a[imax,j]; a[imax,j]:=a[imin,j]; a[imin,j]:=c количество [ и ] одинаково Введите строку 2: Просто [ пример ]] со [[ скобками В строке Просто [ пример ]] со [[ скобками количество [ и ] не одинаково
#include lt;iostreamgt;
#include lt;cstringgt;
#include lt;vectorgt;
#include lt;algorithmgt;
struct StudentData
{
std::string name;
std::string surname;
int math;
int phys;
int comp_science;
};
bool
comp(const StudentData amp;a, const StudentData amp;b)
{
int tmp1 = a.math + a.phys + a.comp_science;
int tmp2 = b.math + b.phys + b.comp_science;
return tmp1 gt; tmp2 true : false;
}
int
main(void)
{
int n;
std::cin gt;gt; n;
std::vectorlt; StudentData gt; data(n);
for (int i = 0; i lt; n; i++) {
std::cin gt;gt; data[i].name gt;gt; data[i].surname;
std::cin gt;gt; data[i].math gt;gt; data[i].phys gt;gt; data[i].comp_science;
}
std::sort(data.begin(), data.end(), comp);
for (int i = 0; i lt; n; i++) {
std::cout lt;lt; data[i].name lt;lt; " " lt;lt; data[i].surname lt;lt; std::endl;
}
return 0;
}
Объяснение: