Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
考的就是完全二叉树啊#include <stdio.h> #define MAX 260 char a[MAX]; int power(int x,int n) { if(n==0)return 1; return x*power(x,n-1); } int main() { int n,j,i,len,count,index; char s[8],c; char o[MAX]; count=1; while(scanf("%d",&n)!=EOF&&n!=0) { for(i=0;i<n;i++)scanf("%s",s); scanf("%s",a); scanf("%d",&len); for(i=0;i<len;i++) { scanf("%s",s); //printf("%s\n",s); for(j=0,index=1;j<n;j++) { if(s[j]=='0')index=index*2; else index=index*2+1; } o[i]=a[index-power(2,n)]; //printf("o[i] %c %d\n",o[i],index); } o[i]='\0'; printf("S-Tree #%d:\n",count); printf("%s\n\n",o); count++; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator