Advertisement
Latkoski

Букви

May 28th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. package bukvi;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.Stack;
  7.  
  8. public class Bukvi {
  9.     public static void main(String[] args) throws IOException {
  10.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  11.         String niza = br.readLine();
  12.         Stack<Character> stek = new Stack<>();
  13.         int brojac = 0;
  14.         int push = 0;
  15.         for (int i = 0; i < niza.length(); i++) {
  16.             if (niza.charAt(i) == 'S') {
  17.                 push = 1 - push;
  18.             }
  19.             if (niza.charAt(i) == 'T') {
  20.                 if (push == 1)
  21.                     stek.push('T');
  22.                 else if (stek.isEmpty()) {
  23.                     System.out.println("0");
  24.                     return;
  25.                 }
  26.                 else if(push == 0)
  27.                     stek.pop();
  28.             }
  29.  
  30.         }
  31.         if (stek.isEmpty())
  32.             System.out.println("1");
  33.         else
  34.             System.out.println("0");
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement