Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

考的就是完全二叉树啊

Posted by StepByStepCnmLife at 2015-05-09 19:59:21 on Problem 1105
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator