#include <iostream> #include <cmath> #include <cstring> using namespace std; const int MAXN = 7+5; const int MAXN1 = 1024; int n, m; int WEIGHT[MAXN]; Save the order of Xi in Char TERMINAL[MAXN1]; Char VARIBLE[MAXN]; The input value before the sort, sorted by weight array content char VARIBLE2[MAXN]; , sorted input value void non_terminal ()//input XI {string s; for (int i = 1; I <= n; i++) {cin >> S; if (s[0] = = ' x ') weight[ I] = s[1]-' 0 '; } void Resort () {for (int i = 1; I <= n; i++) {varible2[i] = Varible[weight[i]];} void print () {int k = 1; int i = 1; I <= N; i++) {if (varible2[i] = = ' 0 ') k = k*2-1; else k = k*2;} cout << terminal[k-1]; int main () {int count = 1 while (cin>>n && n!= 0) {//Initialize memset (weight, 0, sizeof (weight)); memset (ter minal, 0, sizeof (terminal)); Non_terminal (); CIN >> Terminal; CIN >>m; cout << "S-tree #" << Count << ": <<endl; while (m--) {for (int i = 1; I <= n; i++) cin >> Varible[i]; resort (); print ();} cout<<endl<<endl; count++; return 0; } </cstring></cmath></iostream>
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.