UVA 712-s-trees

Source: Internet
Author: User
Tags pow
UVA 712-s-trees

The main topic: give a certain depth of the slow binary tree, each leaf node corresponding value, give the path, the output of the value, 0 is the left subtree, 1 is the right sub-tree

The idea of solving problems: Using POW (2,n) to make it easy to get the last position of the path

#include <stdio.h> #include <iostream> #include <string> #include <sstream> #include <math.h
> Using namespace std;
    int main () {int n;
    int g = 0;
        while (CIN >> n && n! = 0) {g++;
        GetChar ();
        int a[10];
            for (int i = n-1; I >= 0; i--) {int k;
            GetChar ();
            Cin >> K;
            A[k] = i;

        GetChar ();
        } Char s[1000];
        Gets (s);
        int m;
        int b[1000];
        Cin >> m;
        GetChar ();
            for (int i = 0; i < m; i++) {int s = 0;
            Char s2[1000];
            Gets (S2);
            for (int j = 1; J <= N; j + +) {s = s + (s2[j-1]-' 0 ') * POW (2, a[j]);
        } B[i] = s;
        } printf ("S-tree #%d:\n", g);
        for (int i = 0; i < m; i++) {printf ("%c", S[b[i]]);


    } printf ("\ n");
} return 0;
 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.