Uva_712-S-Trees

Source: Internet
Author: User

[Cpp]
/** The question is scared at first glance. It is not difficult to find the question at the end,
* A full binary tree with no more than eight layers is provided, and then 0 goes to the left, 1
* Go to the right and enter x1, x2 ...... Xn (n = depth)
*/
# Include <cstdio>
# Include <cstring>
# Include <cmath>
Using namespace std;
 
# Define MAX 1024 www.2cto.com
 
Char ans [MAX], str [MAX], search [MAX], x [MAX];
 
Int main (int argc, char const * argv [])
{
# Ifndef ONLINE_JUDGE
Freopen ("test. in", "r", stdin );
# Endif
Int depth, cas, cnt (1 );
Char c;
While (~ Scanf ("% d", & depth )){
If (! Depth) return 0;
Memset (ans, '\ 0', sizeof (ans ));
For (int I = 0; I <depth; I ++ ){
Getchar ();
Scanf ("% c % d", & c, & x [I]);
}
Scanf ("% s", str );
Scanf ("% d", & cas );
For (int I = 0, pos; I <cas; I ++ ){
Pos = 0;
Scanf ("% s", search );
For (int j = 0; j <depth; j ++ ){
If (search [x [j]-1]-'0 ')
Pos + = pow (2, depth-j-1 );
}
Ans [I] = str [pos];
}
Printf ("S-Tree # % d: \ n", cnt ++ );
Puts (ans );
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.