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.
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner s = new Scanner(System.in);
int n = s.nextInt();int past = 0;String arr = new String();ArrayDeque<String> a= new ArrayDeque();
String str = "";
StringBuilder sx = new StringBuilder(str);
while(n!=0){
int choice = s.nextInt();
if(choice==1){
arr = sx.toString();a.addLast(arr);
sx.append(s.next());
past = 1;
}
else if(choice==2){
int del = s.nextInt();
arr = sx.toString();a.addLast(arr);
sx.delete(sx.length()-del,sx.length());
past = 2;
}
else if(choice==3){
int k = s.nextInt()-1;
System.out.println(sx.charAt(k));
}
else{
if(past==1)sx = new StringBuilder(a.pollLast());
if(past==2)sx = new StringBuilder(a.pollLast());
}
n--;
//System.out.println("Choice = "+choice+" "+sx+" "+arr);
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Simple Text Editor
You are viewing a single comment's thread. Return to all comments →
JAVA
import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;
public class Peee {
}