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

用string不过,用字符数组过,悲催。

Posted by exmorning at 2011-02-02 01:29:38 on Problem 2255
#include<iostream>
#include<string>
#include<queue>
using namespace std;
char pre[30], mid[30];
queue<char> Q;
int i;
int findInMid()
{
	int j = 0;
	while(pre[i] != mid[j])
		j++;
	i++;
	return j;
}
bool postOrder(int left, int right)
{
	if(left > right)
		return 1;
	int j = findInMid();
	if(postOrder(left, j - 1) && postOrder(j + 1, right))
		Q.push(mid[j]);
}
void print()
{
	while(!Q.empty())
	{
		cout<<Q.front();
		Q.pop();
	}
	cout<<endl;
}
int main()
{
	while(cin>>pre>>mid)
	{
		i = 0;
		postOrder(0, strlen(pre) - 1);
		print();
	}
	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