-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLetters.java
More file actions
67 lines (53 loc) · 1.11 KB
/
Letters.java
File metadata and controls
67 lines (53 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.NoSuchElementException;
//Here's only the Main class. The classes for the data structure implementation are deleted for author rights!
public class StackBukvi {
public static int Funkcija(LinkedStack<Character> obj)
{
int flag=0;
int izbrojaniT=0;
int brojach=0;
while(!obj.isEmpty())
{
if(obj.peek()=='T')
{
obj.pop();
brojach++;
}else if(obj.peek()=='S'){
obj.pop();
if(flag==0)
{
flag=1;
izbrojaniT=brojach;
brojach=0;
}else {
if(izbrojaniT!=brojach)
{
return 0;
}
}
brojach=0;
}
}
return 1;
}
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s;
int i;
s=br.readLine();
LinkedStack<Character> obj=new LinkedStack<Character>();
for(i=0;i<s.length();i++)
{
if(s.charAt(i)=='S' || s.charAt(i)=='T')
{
obj.push(s.charAt(i));
}
}
int a=Funkcija(obj);
System.out.println(a);
}
}