11269

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
2.1 kB
4
Indexable
Never
#include <stdio.h>
#include <string.h>
char ans[505];
char str[505];
char tmp[505];
char tmp2[505];
int a=0;

int main(){
    //int ii = 0 ;
    fgets(str, 500, stdin);
    
    memset(tmp,'\0',505);
    memset(ans,'\0',505);
    int lens = strlen(str);


    int flag=0;

    for(int i=0;i<lens;i++){
        if(str[i]!='\n'){
            int lena = strlen(ans);       
            if(str[i] == '/'){
                for(int j=0;j<9;j++){
                    tmp[j] = str[i+j+1];
                }

                if(strcmp(tmp,"backspace") >=0 && strcmp(tmp,"backspacf") <0){
                    if(a>0) a--;
                    i += 9;
                    lena = strlen(ans);
                    for(int k=a;k<lena;k++) ans[k] = ans[k+1];
                }
                else if(strcmp(tmp,"newline") >=0 && strcmp(tmp,"newlinf") <0){
                    if(flag!=0 && ans[a]!='\0'){
                        int lena = strlen(ans);
                        for(int k=lena+1;k>a;k--){
                            ans[k] = ans[k-1];
                        }
                    }
                    ans[a] = '\n'; a++;
                    i += 7;
                }
                else if(strcmp(tmp,"left") >=0 && strcmp(tmp,"lefu") <0){
                    if(a>0) a--;
                    i += 4; 
                    flag++;

                }
                else if(strcmp(tmp,"right") >=0 && strcmp(tmp,"righu") <0){
                    lena = strlen(ans);
                    
                    if(a<lena) a++;
                    i += 5;
                    flag--;
                }
                
            }
            else  {
                if(flag!=0){
                    int lena = strlen(ans);
                    for(int k=lena+1;k>a;k--){
                        ans[k] = ans[k-1];
                    }
                }
                ans[a] = str[i]; a++;
                
            }
        }
    }
    //printf("%d",strlen(ans));
    printf("%s", ans);

    return 0;
}