Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
用string不过,用字符数组过,悲催。#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator