1011 - nodenum for(i=0;i<nodenum;i...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<cstdio> #include<vector> #include<utility> # using namespace std; u int signum, validnum,transnum; int nodenum; int tree[4096]; i vector< pair<int,int> > matrix[16][12]; v int travel(int node, int signal){ int child; i vector< pair<int,int> > &vec = matrix[signal][tree[node]]; vector< pair<int,int> >::iterator iter; v child = node *2 + 1; if(child >= nodenum || tree[child] ==-1 ){ /* Leaf node */ for(iter = vec.begin(); iter!= vec.end(); iter++){ return 1; } return 0; } for(iter = vec.begin(); iter!= vec.end(); iter++){ return 1; } return 0; } void fun(){ int level; int i; char alpha; scanf("%d ", &level); while(level != -1){ nodenum = 1<<(level+1);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: nodenum--; for(i=0;i<nodenum;i++){ scanf("%c ", &alpha); if(alpha == '*'){ tree[i] = -1; } else { tree[i] = alpha -'a'; } } if(travel(0,0)){ printf("Valid\n"); } else { printf("Invalid\n"); } } scanf("%d ", &level); } } int main(){ int i,j,a,b; char end; int tstcase = 0; scanf("%d %d %d ", &signum, &validnum, &transnum); while(signum ){ validnum = signum - validnum; for(i=0;i<signum;i++){ for(j=0;j<transnum;j++){ matrix[i][j].clear(); do { scanf("%d %d%c", &a,&b,&end); matrix[i][j].push_back( make_pair(a,b) ); } while(end != '\n'); } } } if(tstcase ++){ printf("\n"); } printf("NTA%d:\n", tstcase); p fun(); f scanf("%d %d %d ", &signum, &validnum, &transnum); } return 0; }...
View Full Document

Page1 / 2

1011 - nodenum for(i=0;i<nodenum;i...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online