You are viewing a single comment's thread. Return to all comments →
why this code gives TLE in C
struct stack{ char *str; } stack[10000000]; int len=0; void push(char *arr){ stack[len].str=(char *)calloc(strlen(arr),sizeof(char)); strcpy(stack[len].str,arr); len++; } char* pop(){ len--; return stack[len].str; } int main() { char arr[10000000]=""; int q,k; scanf("%d",&q); while(q--){ int n; scanf("%d",&n); switch(n){ case 1: push(arr); char s[10000000] ; scanf("%s",s); strcat(arr,s); break; case 2: push(arr); scanf("%d",&k); arr[strlen(arr) -k]='\0'; break; case 3: scanf("%d",&k); printf("%c\n",arr[k-1] ); break; case 4: strcpy(arr,pop()); break; } }
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 →
why this code gives TLE in C