首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

foj题目1512,一直runtime error,哪位高手能帮小弟我看上,是不是递归出错了

2012-10-18 
foj题目1512,一直runtime error,谁能帮我看下,是不是递归出错了?Problem DescriptionOaiei is now studyin

foj题目1512,一直runtime error,谁能帮我看下,是不是递归出错了?
Problem Description

Oaiei is now studying Compiler Principles. He finds that compilers must convert each of the statement into a syntax tree for analysis.

A syntax tree is a binary tree. Its leaf node is a variable or is a numerical and each internal node is an operator.

Now your task is, given a syntax tree, convert it into a statement.

Each leaf node is only a letter (a-z or A-Z) or a number (0-9). Operators can only be one of =, +, -, x, / and %.

It’s simple, isn’t it?
Input
The input consists of several test cases. For each case, the first line has an integer n (1<=n<=101), indicating the number of nodes in the given syntax tree, nodes are numbered 1, 2, ..., n. Next n lines, each line consists of three integers A,B,C, indicating the node numbered A has a left child numbered B, a right child numbered C. 0 indicates the node doesn’t have a left or right child. Following C, there is a character D, indicating the value of the node. All nodes are given in layer order.
Output
The statement after coverting the syntax tree. No blanks allowed. (The conversion order is left subtree first and then right subtree)
Sample Input
7 1 2 3 = 2 0 0 a 3 4 5 + 4 0 0 b 5 6 7 + 6 0 0 c 7 0 0 d
Sample Output
a=b+c+d 

C/C++ code
#include<stdio.h>int a[102][3];void in_order(int root){    if(a[root][0]!=0)       in_order(a[root][0]);    printf("%c",a[root][2]);    if(a[root][1]!=0)        in_order(a[root][1]);}void main(){    int n,i,m,r,d;    char k;    while(scanf("%d",&n)!=EOF)    {                for(i=1;i<=n;i++)        {            scanf("%d%d%d",&d,&m,&r);            while(scanf("%c",&k),k==' '||k=='\n');            a[i][0]=m;            a[i][1]=r;            a[i][2]=k;                    }        in_order(1);        printf("\n");    }}


[解决办法]
你试试啊

热点排行