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.
#include<stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>structstack{char*ar;structstack*next;};structstack*pop(structstack*top);structstack*push(char*a,int,structstack*top);intmain(){structstack*top=NULL;//printf("I am here 2");chars[2000002]="";intp;//printf("I am here 3");scanf("%d",&p);//printf("%d\n",strlen(s));top=push(s,strlen(s),top);while(p!=0){intt,i;intlen=strlen(s);//printf("len=%d",len);scanf("%d",&t);switch(t){case1:{char*w=(char*)malloc(1000002*sizeof(char));top=push(s,len,top);scanf("%s",w);strcat(s,w);free(w);break;}case2:{intd;top=push(s,len,top);scanf("%d",&d);s[len-d]=NULL;break;}case3:{intd;scanf("%d",&d);printf("%c\n",s[d-1]);break;}case4:{// printf("stack=%s",top->ar);strcpy(s,top->ar);// printf("s=%s",s);top=pop(top);break;}}p--;}}structstack*push(chara[],intlen,structstack*top){structstack*temp=(structstack*)malloc(sizeof(structstack));temp->ar=(char*)malloc((len+3)*sizeof(char));if(temp==NULL){printf("Memory not available");return;}strcpy(temp->ar,a);// printf("%s",temp->ar);if(top==NULL){top=temp;temp->next=NULL;returntop;}temp->next=top;top=temp;returntop;}structstack*pop(structstack*top){if(top==NULL){printf("To few argue ments to use this func\n");returnNULL;}structstack*temp=top;top=top->next;free(temp);returntop;}
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 →