fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(void) {
  5. int g=0;
  6.  
  7. char s[10000]={'\0'};
  8. while(~scanf("%s",s+1)){
  9. int last, cur, next[10000]={0};
  10. int n=strlen(s+1);
  11. last=0;
  12. cur=0;
  13.  
  14.  
  15. next[0]=0;
  16.  
  17. for(int i=1;i<=n;i++){
  18. char ch=s[i];
  19. if(ch == '['){cur=0;}
  20. else if(ch == ']'){cur=last;}
  21. else{
  22. next[i]=next[cur];
  23. next[cur]=i;
  24. if(cur==last) last=i;
  25. cur=i;
  26. }
  27. }
  28.  
  29. char t[10000]={'\0'};
  30. int k=0;
  31. for(int ii=next[0];ii!=0;ii=next[ii]){
  32. t[k++]=s[ii];
  33.  
  34. }
  35.  
  36. int ct=0;
  37.  
  38. for(int j=0;j<=strlen(t);j++){
  39.  
  40. if(t[j]=='^'){
  41. ct+=1;
  42.  
  43.  
  44. if(t[j+1]!='^'){
  45.  
  46. for(int jct=(j-ct*2+1);jct<j+1;jct++){
  47.  
  48. t[jct]='@';
  49.  
  50. }
  51. ct=0;
  52. }
  53.  
  54. }
  55. }
  56.  
  57. for(int kk=0;kk<strlen(t);kk++){
  58.  
  59. if(t[kk]!='@' && t[kk]!='\0'){printf("%c",t[kk]);}
  60.  
  61. }
  62.  
  63.  
  64.  
  65. printf("\n");
  66.  
  67. }
  68. return 0;
  69. }
Success #stdin #stdout 0s 9424KB
stdin
Welcome_[to]_NCCU
[][[]]]]Hello_world
Hello_C^^
stdout
toWelcome__NCCU
Hello_world
Hello