POJ 2255

水题

只是zz的我卡了好久

  1. 函数传递的只是值。。。
  2. malloc函数不会启用结构的构造函数

原先使用节点构造树

后来觉得刘汝佳的代码思路更简洁(然而他的黑书错实在太多了...)
这是最后简洁版的,string构造(str, head, len)切记,不知道这个又卡了一会...

#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
using namespace std;

void opt(string a, string b)
{
	int len= a.length();
	if (len< 1){
		return;
	}
	int pos= b.find(a[0]);
	if (pos> 0){
		string al(a, 1, pos), bl(b, 0, pos);
		opt(al, bl);
	}
	if (len-1> pos){
		int l= len-pos-1;
		string ar(a, pos+1, l), br(b, pos+1, l);
		opt(ar, br);
	}

	putchar(a[0]);
}
int main()
{
	string ar, br;
	while( cin>>ar ){	
		cin>>br;
		opt(ar, br);
		putchar('
');
	}
	return 0;
}

// pos len_left_tree
原文地址:https://www.cnblogs.com/Idi0t-N3/p/12563993.html