-
Notifications
You must be signed in to change notification settings - Fork 0
/
texto sequencial.java
104 lines (90 loc) · 2.67 KB
/
texto sequencial.java
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
class NoPilha{
protected NoPilha next;
private String frase;
public NoPilha(String frase){
this.frase=frase;
}
public String getFrase(){
return this.frase;
}
}
class Pilha{
protected NoPilha pilha;
private int quantidade;
public int size(){
return quantidade;
}
public void push(String frase){
if(size()==0){
pilha = new NoPilha(frase);
}else{
NoPilha temp = pilha;
pilha = new NoPilha(frase);
pilha.next = temp;
}
quantidade++;
}
public String peek(){
return pilha.getFrase();
}
public String pop(){
String r = pilha.getFrase();
pilha = pilha.next;
quantidade--;
return r;
}
}
public class Solution {
static Pilha pilha = new Pilha();
static Boolean quemAchouQueTratarDasAspasEraUmaBoaIdeia = false;
public static void inserir(String t){
quemAchouQueTratarDasAspasEraUmaBoaIdeia = t.contains("\"");
String r = t;
if(pilha.size()!=0){
if(quemAchouQueTratarDasAspasEraUmaBoaIdeia){
r = "\"" + pilha.pilha.getFrase().replaceAll("\"","") + t.replaceFirst("\"","");
}else{
r = pilha.pilha.getFrase() + t;
}
}
pilha.push(r);
}
public static void alteracoes(){
NoPilha temp = pilha.pilha;
System.out.print("Topo");
while(temp!=null){
System.out.print("->" + temp.getFrase());
temp = temp.next;
}
System.out.println();
}
public static void desfazer(){
String r = pilha.pop();
}
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String a = bufferedReader.readLine();
String b = bufferedReader.readLine();
String c = bufferedReader.readLine();
Solution.inserir(a);
Solution.alteracoes();
Solution.inserir(b);
Solution.alteracoes();
Solution.inserir(c);
Solution.alteracoes();
Solution.desfazer();
Solution.alteracoes();
bufferedReader.close();
}
}