1 条题解

  • 0
    @ 2021-6-14 23:29:18

    C :

    #include <stdlib.h>
    void root( char *mid, char *last )
    {
        char a,*x,*y;
    
        if(!*mid)
            return; 
        x= last+strlen(last)-1;
        printf("%c",*x);
    
        y=strchr(mid,*x);    
        *x=0x0;
        x=y-mid+last;
        a=*x;
        *x=0x0;
        *y=0x0;
    	root(mid,last);
        *x=a;
        root( y+1,x);
    }
    
    
    int main()
    {
        char mid[50];
        char last[50];
    	scanf("%s%*c%s%*c",mid,last);
    	root(mid,last);
        printf( "\n" );
    
        return 0;
    }
    

    C++ :

    #include <iostream>
    #include <string.h>
    using namespace std;
    void build(int n,char* s1,char* s2){
    	if(n<=0)	return;
    	int p=strchr(s2,s1[n-1])-s2;
    	cout<<s1[n-1];
    	build(p,s1,s2);
    	build(n-1-p,s1+p,s2+p+1);
    }
    int main()
    {
    	char s1[100],s2[100];
    	while(cin>>s2>>s1)
    	{
    		int n=strlen(s1);
    		build(n,s1,s2);
    		cout<<endl;
    	}
    	return 0;
    }
    

    Pascal :

    var s1,s2:string;
    procedure dfs(mid,last:string); 
    var root:string;i:longint; 
    begin
      if (mid='')and(last='') then exit; 
      root:=last[length(last)]; 
      write(root); 
      for i:=1 to length(last) do
        if mid[i]=root then break; 
      dfs(copy(mid,1,i-1),copy(last,1,i-1)); 
      dfs(copy(mid,i+1,length(mid)-i),copy(last,i,length(last)-i));
    end; 
    begin
      readln(s1); 
      readln(s2);
      dfs(s1,s2); 
      writeln;
    end.
    
    
    • 1

    信息

    ID
    209
    时间
    1000ms
    内存
    125MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者