Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
record XY(int x, int y) {}
List<XY> a = new ArrayList<>();
int x, y, m = s.length(), n, c;
for (x = 0; x != m; ++x)
if (s.charAt(x) == '{')
for (y = x + (n = 1); y != m; ++y)
if ((c = s.charAt(y)) == '{') ++n;
else if (c == '}' && --n == 0) {
a.add(new XY(x, y));
break;
}
var
i, k,B,Len: Integer;
List: array of integer;
c: Char;
const
S = '{.{.}.}.{.}';
begin
SetLength(List,Length(S));
Len:=Length(S);
for i:=1 to Len do begin
if S[i]='{' then begin
B:=0;
for k:=i+1 to Len do begin
c:=S[k];
if c='{' then
Inc(B)
else
if c = '}' then begin
if (B<=0) then Break;
Dec(B);
end;
end;
List[i-1]:=k-1;
end
else
List[i-1]:=-1;
end;
end.
a = []
length = len(s)
for index, value in enumerate(s):
if value == '{':
count = 1
for n in range(index + 1, length):
match s[n]:
case '{':
count += 1
case '}':
count -= 1
if not count:
a.append((index, n))
break