UVa 712 - S-Trees

传送门UVa 712 - S-Trees

做的第一题关于树的题目.

题目乍一看很吓人, 但是我真的被他吓到了. 于是我可耻地去看了解题报告.(ˉ▽ ̄~)

题意是给你一串数字, 0就是往左, 1往右, 让你求最后落到叶子上的编号.

还有一个什么variable ordering , 也就是x后面的数字组成的数组, 如果是x3, x1, x2, 输入为001, 第一次就是1, 第二次和第三次是0.哎..表达不清楚. 大学不学语文, 语言能力都退化了.

具体看代码吧..不会表达了


#include <cstdio>
#include <cstring>
#include <vector>
#include <cstdlib>

using namespace std;

void Calc();

int n, m;
char termi[200];
vector <int> order;

int main()
{
    //freopen("input.txt", "r", stdin);
    int cnt = 1;
    while (scanf("%d", &n) == 1)
    {
        if (n == 0)
            break;
        printf("S-Tree #%d:\n", cnt++);
        Calc();
    }
    return 0;
}
void Calc()
{
    char temp[10];
    char vva[200];
    int i, val;
    int m;
    order.clear();
    for (i = 0; i < n; i++)
    {
        scanf("%s", temp);
        sscanf(temp + 1, "%d", &val);
        order.push_back(val);
    }
    scanf("%s", termi);
    scanf("%d", &m);
    getchar();
    while (m--)
    {
        int pos = 1;
        scanf("%s", vva + 1);
        for (i = 0; i < order.size(); i++)
        {
            if (vva[order[i]] == '0')
                pos *= 2;
            else
                pos = pos * 2 + 1;
        }
        printf("%c", termi[pos - (1 << n)]);
    }
    printf("\n\n");
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值