题目有点长,但是思路很简单,找出每次的路径2进制序列然后在叶子里找到对应的0或1值即可。
#include<stdio.h> #include<stdlib.h> #include<math.h> int orders[10]; char leaves[200]; int num=1; int main() { int n; char str[10]; while (scanf("%d", &n) != EOF) { if (n == 0) break; printf("S-Tree #%d:\n",num++); int i; for (i = 0; i < n; i++) { scanf("%s", str); orders[i] = atoi(str + 1); } scanf("%s", leaves); int m; scanf("%d", &m); char vva[10]; for (i = 0; i < m; i++) { scanf("%s", vva); int j; char binary[10]; for (j = 0; j < n; j++) { binary[j] = vva[orders[j] - 1]; } binary[n] = 0; int idx = 0; int k; for (k = 0; k < n; k++) { if (binary[k] - '0') idx += pow(2, n - 1 - k); } printf("%d", leaves[idx]-'0'); if (i == m - 1) printf("\n\n"); } } return 0; }
相关推荐
判断输入字符串是否为镜像或回文串。 来源于UVaOJ - 401. 水题。
开源项目-codingsince1985-UVa#uva-online-judge-solutions-in-golang.zip,两年来每天都在解决一个uva在线裁判问题,算起来…
uva705 Slash Maze 的代码,在UVaOJ上通过
PDF试题
Algorithm-UVA-Solutions-in-Python.zip,python 3中各种uva(acm)问题的解决方案。,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
uva532 Dungeon Master的源代码,并且AC了
这是UVA133 TheDoleQueue救济金发放问题,经典的算法问题。初学算法的人要对这种算法非常熟悉并且能熟练运用。
tpcw-nyu-uva-client 客户端
leetcode 2 算法-Java UVa Online Judge(ACM-ICPC Live ...使用:数组、哈希表、链表、二分搜索、动态规划、堆栈、堆、reedy、排序、树 DFS、BFS、图、二分搜索树、递归、记忆、队列、映射等。...Uva-ACM-ICPC