We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Simple Text Editor
Simple Text Editor
Sort by
recency
|
539 Discussions
|
Please Login in order to post a comment
include
include
include
include
include
include
using namespace std;
int main() { string S1 = ""; int Queries = 0; cin >> Queries; int Operations = 0; string S2 = ""; stack Temp; while (Queries--) { cin >> Operations; if (Operations == 1) { Temp.push(S1); cin >> S2; S1 += S2; } else if (Operations == 2) { Temp.push(S1); cin >> Operations; S1.erase(S1.size() - Operations, S1.size()); } else if (Operations == 3) { cin >> Operations; cout << S1[Operations-1] << endl;; } else if (Operations == 4) { S1 = Temp.top(); Temp.pop(); } } }
For Java 7. Ok. You need to know that i generated this by chatGPT, tell him to optimize my oringinal. Eventhrough it's still not good enough, but try a few times then it might pass.
import java.util.Scanner; import java.util.Stack;
public class SolutionSolution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int q = scanner.nextInt(); scanner.nextLine();
static class Operation { int type; // 1 for append, 2 for delete int length; String data;
}
Simple cpp solution:
JavaScript (NodeJS) Solution