Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class a {
  5.  
  6. static FastReader in = new FastReader();
  7. static PrintWriter out = new PrintWriter(System.out);
  8.  
  9.  
  10. public static void main(String[] args) throws Exception {
  11. int tc = 1;
  12. while (true) {
  13. String s = in.next();
  14. if (s.charAt(0) == '-') {
  15. break;
  16. }
  17. int cnt = 0, ans = 0;
  18. for (int i = 0; i < s.length(); i++) {
  19. if (s.charAt(i) == '{') {
  20. cnt++;
  21. } else {
  22. cnt--;
  23. }
  24. if (cnt < 0) {
  25. cnt = 1;
  26. ans++;
  27. }
  28. }//for
  29. out.printf("%d. %d\n", tc++, ans + cnt / 2);
  30. }//while
  31. out.flush();
  32. }//psvm
  33.  
  34. static class FastReader {
  35.  
  36. BufferedReader br;
  37. StringTokenizer st;
  38.  
  39. FastReader() {
  40. br = new BufferedReader(new InputStreamReader(System.in));
  41. }
  42.  
  43. FastReader(File f) {
  44. try {
  45. br = new BufferedReader(new FileReader(f));
  46. } catch (FileNotFoundException x) {
  47. x.printStackTrace();
  48. }
  49. }
  50.  
  51. String next() throws IOException {
  52. while (st == null || !st.hasMoreTokens()) {
  53. st = new StringTokenizer(br.readLine());
  54. }
  55. return st.nextToken();
  56. }
  57.  
  58. String nextLine() throws IOException {
  59. return br.readLine();
  60. }
  61.  
  62. int nextInt() throws IOException {
  63. return Integer.parseInt(next());
  64. }
  65.  
  66. long nextLong() throws IOException {
  67. return Long.parseLong(next());
  68. }
  69.  
  70. double nextDouble() throws IOException {
  71. return Double.parseDouble(next());
  72. }
  73.  
  74. boolean hasNext() throws IOException {
  75. String s = br.readLine();
  76. if (s == null) {
  77. return false;
  78. }
  79. st = new StringTokenizer(s);
  80. return true;
  81. }
  82. }
  83. }//class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement