UVA 712(p176)----S-Trees

来源:互联网 发布:115会员淘宝不卖了 编辑:程序博客网 时间:2024/06/10 18:10
#include<bits/stdc++.h>#define debuusing namespace std;int v[10],n,m;string lf;char solve(string st){    int d=1;    for(int i=0; i<n; i++)        if(st[v[i]]=='0')  d*=2;        else d=d*2+1;    return lf[d-(1<<n)];}int main(){#ifdef debug    freopen("in.in","r",stdin);#endif // debug    int cas=0;    string tmp;    while((cin>>n)&&n)    {        cout<<"S-Tree #"<<++cas<<":\n";        for(int i=0; i<n; i++)        {            cin>>tmp;            v[i]=tmp[1]-'1';        }        cin>>lf>>m;        for(int i=0; i<m; i++)        {            cin>>tmp;            cout<<solve(tmp);        }        cout<<"\n\n";    }    return 0;}
题目地址:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=653

0 0
原创粉丝点击