6 solutions

  • 11
    @ 2023-12-15 22:56:32

    这个题与 A1339 的不同之处在于,根据中序遍历序列来看,层次遍历序列并不是连续的,因此必须在整个层次遍历序列中找一遍。

    • 8
      @ 2023-12-19 20:16:58
      #include<iostream>
      using namespace std;
      string z,c;
      int len;
      
      int find(int L, int R) {
          for(int i=0;i<len;i++){
              for(int j=L;j<=R;j++){
                  if(c[i]==z[j])
                  return j;
              }
          }
      }
      
      void f(int l,int r){
      	int m=find(l,r);
      	cout<<z[m];
      	if(m>l)f(l,m-1);
      	if(r>m)f(m+1,r);
      }
      int main(){
      	cin>>z;
      	cin>>c;
      	len=c.size();
      	f(0,z.size()-1);
      	
      }
      
      • 0
        @ 2023-12-19 20:17:16
        #include<iostream>
        using namespace std;
        string z,c;
        int len;
        
        int find(int L, int R) {
            for(int i=0;i<len;i++){
                for(int j=L;j<=R;j++){
                    if(c[i]==z[j])
                    return j;
                }
            }
        }
        
        void f(int l,int r){
        	int m=find(l,r);
        	cout<<z[m];
        	if(m>l)f(l,m-1);
        	if(r>m)f(m+1,r);
        }
        int main(){
        	cin>>z;
        	cin>>c;
        	len=c.size();
        	f(0,z.size()-1);
        	
        }
        
        
        • -1
          @ 2023-12-20 16:54:04
          #include
          #include <string>
          using namespace std;
          string zhong;
          string ceng;
          
          //int find(int l,int r)
          //{
          //	for (int i=0;i<ceng.length();i++)
          //	{
          //		for (int j=l;j<=r;j++){
          //			if (ceng[i]==zhong[j]){
          //				return j;
          //			}
          //		}
          //	}	
          //}
          
          void f(int l,int r)
          {
          	//cout << l << "\t" << r <<endl;
          	int mid=0;
          	for (int i=0;i<ceng.length();i++)
          	{
          		bool flag=true;
          		for (mid=l;mid<=r;mid++){
          			if (ceng[i]==zhong[mid]){
          				flag=false;
          				break;
          			}
          		}
          		if (flag==false)
          		{
          			break;	
          		}
          	}	
          	cout << zhong[mid];
          	if(l<mid){
          		f(l,mid-1);
          	}
          	if(mid<r){
          		f(mid+1,r);	
          	}
          }
          
          int main()
          {
          	cin >> zhong;
          	cin >> ceng;
          	f(0,zhong.length()-1);
           }
          
          • -1
            @ 2023-12-19 20:18:23
            #include<iostream>
            using namespace std;
            string z,c;
            int len;
            
            int find(int L, int R) {
                for(int i=0;i<len;i++){
                    for(int j=L;j<=R;j++){
                        if(c[i]==z[j])
                        return j;
                    }
                }
            }
            
            void f(int l,int r){
            	int m=find(l,r);
            	cout<<z[m];
            	if(m>l)f(l,m-1);
            	if(r>m)f(m+1,r);
            }
            int main(){
            	cin>>z;
            	cin>>c;
            	len=c.size();
            	f(0,z.size()-1);
            	
            }
            
            
            • -2
              @ 2023-12-19 20:16:42
              #include<iostream>
              using namespace std;
              string z,c;
              int len;
              
              int find(int L, int R) {
                  for(int i=0;i<len;i++){
                      for(int j=L;j<=R;j++){
                          if(c[i]==z[j])
                          return j;
                      }
                  }
              }
              
              void f(int l,int r){
              	int m=find(l,r);
              	cout<<z[m];
              	if(m>l)f(l,m-1);
              	if(r>m)f(m+1,r);
              }
              int main(){
              	cin>>z;
              	cin>>c;
              	len=c.size();
              	f(0,z.size()-1);
              	
              }
              
              • 1

              Information

              ID
              849
              Time
              1000ms
              Memory
              256MiB
              Difficulty
              5
              Tags
              # Submissions
              84
              Accepted
              30
              Uploaded By