Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class a {
- static FastReader in = new FastReader();
- static PrintWriter out = new PrintWriter(System.out);
- public static void main(String[] args) throws Exception {
- int tc = 1;
- while (true) {
- String s = in.next();
- if (s.charAt(0) == '-') {
- break;
- }
- int cnt = 0, ans = 0;
- for (int i = 0; i < s.length(); i++) {
- if (s.charAt(i) == '{') {
- cnt++;
- } else {
- cnt--;
- }
- if (cnt < 0) {
- cnt = 1;
- ans++;
- }
- }//for
- out.printf("%d. %d\n", tc++, ans + cnt / 2);
- }//while
- out.flush();
- }//psvm
- static class FastReader {
- BufferedReader br;
- StringTokenizer st;
- FastReader() {
- br = new BufferedReader(new InputStreamReader(System.in));
- }
- FastReader(File f) {
- try {
- br = new BufferedReader(new FileReader(f));
- } catch (FileNotFoundException x) {
- x.printStackTrace();
- }
- }
- String next() throws IOException {
- while (st == null || !st.hasMoreTokens()) {
- st = new StringTokenizer(br.readLine());
- }
- return st.nextToken();
- }
- String nextLine() throws IOException {
- return br.readLine();
- }
- int nextInt() throws IOException {
- return Integer.parseInt(next());
- }
- long nextLong() throws IOException {
- return Long.parseLong(next());
- }
- double nextDouble() throws IOException {
- return Double.parseDouble(next());
- }
- boolean hasNext() throws IOException {
- String s = br.readLine();
- if (s == null) {
- return false;
- }
- st = new StringTokenizer(s);
- return true;
- }
- }
- }//class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement