UVA-11234

来源:互联网 发布:wpf编程宝典 2012 pdf 编辑:程序博客网 时间:2024/06/06 04:29
#include<iostream>#include<cstdio>#include<stack>#include<queue>#include<string>#define maxn 10050using namespace std;struct Node{    char c;    int id,u,v;} node[maxn];int T,i,t,sum;Node node1,node2;char ch;string ss[210];string ans,ans1;void init(){    for(int i=0; i<maxn; i++)    {        node[i].u=node[i].v=-1;        node[i].id=i;    }}int main(){    cin>>T;    getchar();    while(T--)    {        getline(cin,ss[i++]);    }    for(int j=0; j<i; j++)    {        init();        t=0;ans="";        stack<char>s;        stack<Node>s1;        int len=ss[j].length();        for(int k=len-1; k>=0; k--)            s.push(ss[j][k]);        while(!s.empty())        {            ch=s.top();            s.pop();            node[t].c=ch;            if(ch>='a'&&ch<='z');            else            {                node[t].v=s1.top().id;                s1.pop();                node[t].u=s1.top().id;                s1.pop();            }            s1.push(node[t]);t++;        }        queue<Node>q;        q.push(node[t-1]);        while(!q.empty())        {            node1=q.front();            ans+=node1.c;            q.pop();            if(node1.u!=-1)            {                q.push(node[node1.u]);                q.push(node[node1.v]);            }        }        int len1=ans.length();        for(int i=len1-1;i>=0;i--)        cout<<ans[i];        cout<<endl;    }    return 0;}

0 0
原创粉丝点击