Balanced brackets: Difference between revisions

m
Line 433:
foreach (int i, char c; s) {
balance += (c == '[' ? 1 : (c == ']' ? -1 : 0));
if (balance < 0) { writeln(` BAD at index %s`, i); continue NEXT_STR; }
}
writeln(` OK!`);// for equal amount of open/closed brackets, balance here is always = 0
Line 441:
 
Output:
<pre>String: [[]][][ BAD at index 4
<pre>
String: ]][][[[] BAD at index 0
String: [][[[][] BADOK!
String: ]][][[] BAD at index 0
String: [[][]]][[ BAD at index OK!0
String: []]][[[] BAD at index 2
String: ]][][[]] BAD at index 0
String: [][[]]][ BAD at index OK!4
String: ][][][] BADOK!
String: [[]]][] BADOK!</pre>
String: []][][ BAD
</pre>
 
=={{header|Euphoria}}==
19

edits