题意
给你一棵完全二叉树,输入0往左走,1往右
思路
由于是二叉树,正好相应二进制数
直接存到字符串里模拟AC代码
#include#include #include using namespace std;int main(){ int T, t, len, i, j, num; string line; char s[1000], f[100]; int casenum = 0; while( scanf("%d",&T) == 1 && T ){ memset(s,0,sizeof(s)); memset(f,0,sizeof(f)); line = ""; printf("S-Tree #%d:\n",++casenum); getchar(); getline(cin,line); scanf("%s",s); scanf("%d",&t); while(t--){ scanf("%s",f); len = strlen(f); num = 0; for( i = len-1, j = 0; i >= 0; i--, j++ ) num += ( f[i] - '0' ) * (1<