//PascalABC.NET 3.1 сборка 1239 var brackets: array [0..2, 0..1] of char := (('{', '}'), ('[', ']'), ('(', ')'));
begin var s := ReadlnString(); var counter := 0; var max_depth := 0;
for var i := 1 to s.Length do begin if s[i] = '(' then counter += 1 else if s[i] = ')' then counter -= 1 else continue; if counter < 0 then begin writeln('brackets error'); Halt; end; if counter > max_depth then max_depth := counter; end;
counter := 0; for var i := 1 to s.Length do begin if s[i] = '(' then counter += 1 else if s[i] = ')' then counter -= 1 else continue;
if (counter = max_depth - 1) and (s[i] = '(') then s[i] := brackets[1, 0] else if (counter = max_depth - 2) and (s[i] = ')') then s[i] := brackets[1, 1] else if (counter = max_depth - 2) and (s[i] = '(') then s[i] := brackets[0, 0] else if (counter = max_depth - 3) and (s[i] = ')') then s[i] := brackets[0, 1]; end;
Var s:string; se1,se2:set of char; i:integer; begin se1:=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_']; se2:=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','0','1','2','3','4','5','6','7','8','9']; readln(s); if not(lowcase(s[1]) in se1) then begin writeln('Не идентификатор'); exit; end; for i:=2 to length(s) do if not(lowcase(s[i]) in se2) then begin writeln('Не идентификатор'); exit; end; writeln('Идентификатор'); end.
Пример ввода: _SomeIdentificator Пример вывода: Идентификатор
var
brackets: array [0..2, 0..1] of char := (('{', '}'), ('[', ']'), ('(', ')'));
begin
var s := ReadlnString();
var counter := 0;
var max_depth := 0;
for var i := 1 to s.Length do
begin
if s[i] = '(' then counter += 1
else if s[i] = ')' then counter -= 1
else continue;
if counter < 0 then begin
writeln('brackets error');
Halt;
end;
if counter > max_depth then max_depth := counter;
end;
counter := 0;
for var i := 1 to s.Length do
begin
if s[i] = '(' then counter += 1
else if s[i] = ')' then counter -= 1
else continue;
if (counter = max_depth - 1) and (s[i] = '(') then s[i] := brackets[1, 0]
else if (counter = max_depth - 2) and (s[i] = ')') then s[i] := brackets[1, 1]
else if (counter = max_depth - 2) and (s[i] = '(') then s[i] := brackets[0, 0]
else if (counter = max_depth - 3) and (s[i] = ')') then s[i] := brackets[0, 1];
end;
writeln(s);
end.
Var
s:string;
se1,se2:set of char;
i:integer;
begin
se1:=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_'];
se2:=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','0','1','2','3','4','5','6','7','8','9'];
readln(s);
if not(lowcase(s[1]) in se1) then
begin
writeln('Не идентификатор');
exit;
end;
for i:=2 to length(s) do
if not(lowcase(s[i]) in se2) then
begin
writeln('Не идентификатор');
exit;
end;
writeln('Идентификатор');
end.
Пример ввода:
_SomeIdentificator
Пример вывода:
Идентификатор