Uva 712 S-Trees

简介: 点击打开链接 #include #include #include #include #include #include #include #include #include #include #include us...

点击打开链接



#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <stack>
#include <list>
#include <algorithm>
using namespace std;

const int MAXN = 1000;
int n , m , sum;
string str[10] , mstr[MAXN];//str用来存储操作的步骤
char num[MAXN];//存储叶子节点的值

//输入函数
void input(){
    for(int i = 0 ;i < n ; i++)
        cin>>str[i];
    cin>>num;
}
//处理函
void solve(int k){
    cin>>m;
    int temp;
    for(int i = 0 ; i < m ; i++)
        cin>>mstr[i];
    printf("S-Tree #%d:\n" , k);
    for(int i = 0 ; i < m ; i++){
         temp = 0;
         for(int j = 0 ; j < n ; j++)
             temp += (mstr[i][j] - 48) * pow(2 , n - j -1);
         printf("%c" , num[temp]);
    }
    cout<<endl<<endl;
}
//主函数
int main(){
    int i = 1;
    while(scanf("%d" , &n) && n){
        sum = pow(2 , n);
        input();
        solve(i);
        i++;
    }
    return 0;
}


目录
相关文章
UVa872 - Ordering(拓扑排序)
UVa872 - Ordering(拓扑排序)
61 0
POJ 1306 Combinations
POJ 1306 Combinations
114 0
|
机器学习/深度学习 自然语言处理
POJ 1306 Combinations
Description Computing the exact number of ways that N things can be taken M at a time can be a great challenge when N and/or M become very large.
643 0
hdu 3015 Disharmony Trees
点击打开hdu 3015 思路: 树状数组 分析: 1 题目给定n棵树的横坐标和高度,然后给定横坐标排序后的rank_f已及树的高度排序后的rank_s,规定两颗树的FAR为abs(rank_f[i] , rank_f[j]) , SHORT为min(rank_s[i] .
918 0