Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

so easy,一把AC的感觉好爽,虽然这题非常之水。。。

Posted by nan5515522 at 2014-04-27 21:39:12 on Problem 2255
C++编译204K,0MSAC的代码
#include<iostream>
#include<Cstdio>


using namespace std;

char pre[500], in[500];
struct Binary 
{
	char ch;
	Binary *left, *right;
};

Binary* build(char a1[], char a2[], int length)
{
	Binary *root = new Binary();
	root -> ch = a1[0];
	root -> left = NULL;
	root -> right = NULL;
	
	int i = 0;
	while(a2[i] != a1[0])
	    i ++;
	int leftLength = i;
	int rightLength = length - i - 1;
	
	if(leftLength > 0)
		root -> left = build(a1 + 1, a2, leftLength);
	
	if(rightLength > 0)
		root -> right = build(a1 + 1 + leftLength, a2 + 1 + leftLength, rightLength);
	
	return root;
	
}

void visit(Binary* root)
{
	if(root->left != NULL)
		visit(root->left);
	if(root->right != NULL)
		visit(root->right);
	
	cout << root->ch;
}
int main()
{
	
	while(cin >> pre)
	{
	cin >> in;
	int i = 0;
	while(1)
	{
		if(pre[i] == '\0')
			break;
		i++;
	}
	
	Binary* root = build(pre, in, i);
	visit(root);
	cout << endl;
	}
   return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator