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.
/*Can some one suggest whats the mistake I made */
import java.io.;
import java.util.;
public class Solution {
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
int q = scanner.nextInt();
StringBuilder sb = new StringBuilder();
Stack st = new Stack();
for(int i=0; i< q; i++){
int oprn = scanner.nextInt();
switch(oprn){
case 1 : {
String W = scanner.next();
st.push(sb.toString());
sb.append(W);
break;
}case 2 : {
st.push(sb.toString());
int k = scanner.nextInt();
st.push(sb.toString());
sb.delete(sb.length() - k, k);
break;
}case 3 :{
int p = scanner.nextInt();
System.out.println(sb.toString().charAt(p-1));
break;
}case 4 :{
sb.delete(0, sb.length());
sb.append(st.pop());
break;
}
}
}
}
}
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 →
/*Can some one suggest whats the mistake I made */
import java.io.; import java.util.;
public class Solution {
}