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.
  • Practice
  • Certification
  • Compete
  • Career Fair
  • Hiring developers?
  1. Practice
  2. Data Structures
  3. Stacks
  4. Simple Text Editor
  5. Discussions

Simple Text Editor

Problem
Submissions
Leaderboard
Discussions

    You are viewing a single comment's thread. Return to all comments →

  • mayank_k_jha 4 years ago+ 0 comments

    Simple java Solution : - :D

    public class Solution {
     public static void main(String[] args) {
           Scanner in=new Scanner(System.in);
           int n=in.nextInt();
           String s = "";
          Stack<String> st =new Stack<String>();
          st.push(s);
            for(int i=0;i<n;i++){
            	 int t=in.nextInt();
                if(t==1){ s = s+in.next();st.push(s);
                   }
                else if(t==2){s=s.substring(0,s.length()-in.nextInt());st.push(s);}
                else if(t==3){System.out.println(s.charAt(in.nextInt()-1)); }
                else{st.pop();s=st.peek();}}}}
    
    26|
    Permalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature