Uva - 712 - S-Trees

来源:互联网 发布:域名在哪里购买 编辑:程序博客网 时间:2024/06/07 05:05




第一次不小心用printf输出WA了,还是要把输入输出统一起来,切记切记。题目不难,按路径算出叶子结点,最后统一输出就行了。

AC代码:

#include <iostream>#include <cstdio>#include <cstdlib>#include <cctype>#include <cstring>#include <string>#include <sstream>#include <vector>#include <set>#include <map>#include <algorithm>#include <stack>#include <queue>#include <bitset> #include <cassert> #include <cmath>using namespace std;const int maxn = 1000;int n, m, sum;string str[10], mstr[maxn]; // mstr存储操作的步骤char num[maxn]; // 结点的值int main(){ios::sync_with_stdio(false);int kase = 0;while (cin >> n && n) {sum = pow(2, n);// 输入结点for (int i = 0; i < n; i++) {cin >> str[i];}cin >> num;cin >> m;int temp;for (int i = 0; i < m; i++) {cin >> mstr[i];}cout << "S-Tree #" << ++kase << ":\n";//printf("S-Tree #%d:\n", ++kase);for (int i = 0; i < m; i++) {temp = 0;for (int j = 0; j < n; j++) {temp += (mstr[i][j] - '0') * pow(2, n - j - 1);}cout << num[temp];}cout << endl << endl;}return 0;}




0 0
原创粉丝点击