Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bukvi;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.Stack;
- public class Bukvi {
- public static void main(String[] args) throws IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- String niza = br.readLine();
- Stack<Character> stek = new Stack<>();
- int brojac = 0;
- int push = 0;
- for (int i = 0; i < niza.length(); i++) {
- if (niza.charAt(i) == 'S') {
- push = 1 - push;
- }
- if (niza.charAt(i) == 'T') {
- if (push == 1)
- stek.push('T');
- else if (stek.isEmpty()) {
- System.out.println("0");
- return;
- }
- else if(push == 0)
- stek.pop();
- }
- }
- if (stek.isEmpty())
- System.out.println("1");
- else
- System.out.println("0");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement