正文

pku(2567)(1)2005-09-08 04:56:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/ddtme/4508.html

分享到:

#include <iostream> #include <stack> using namespace std; struct node {     int parent;     int child[51];     int du; }nd[51]; void doRun() {     int i,j,k,len,temp,root;     char s[256],b[2];     stack<int> sp;     int p[51];     while(gets(s)!=NULL)     {         for(i=0;i<51;i++)         {             nd[i].du = 1;             nd[i].parent = 0;             for(j=0;j<51;j++)                 nd[i].child[j] = 0;         }         len = 0;         //计算父亲节点和度         sp.push((int)'(');         for(i=1;i<(int)strlen(s);i++)         {             if(isdigit(s[i]))             {                 len++;                                 j=0;                 while(s[i]!=' '&& s[i]!=')')                 {                     b[j++] = s[i];                     i++;                 }                 i--;                 b[j] = '\0';                 temp = atoi(b);                 sp.push(temp);                 if(i==1)                 {                     root = temp;                     nd[root].du--;                 }             }             else if(s[i] == '(')             {                 nd[sp.top()].du++;                 sp.push((int)'(');             }             else if(s[i] == ')')             {                 while(sp.top()!=(int)'(')                 {                     temp = sp.top();                     sp.pop();                 }                 sp.pop();                 if(!sp.empty())                 {                     nd[temp].parent = sp.top();                 }                 else                 {                     nd[temp].parent = 0;                 }             }             else             {                 continue;             }         }         if(len <= 1)         {             if(len==1)                 cout<<endl;             continue;         }

阅读(16151) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册