给定一个如下格式的字符串(1,(2,3),(4,(5,6),7))括号内的元素可以是数字,也可以是另一个括号,请实现一个算法消除嵌套的括号,比如把上面的表达式变成:(1,2,3,4,5,6,7),如果表达式有误请报错。(15分)
/************************************************************************/ /* 给定一个如下格式的字符串(1,(2,3),(4,(5,6),7))括号内的元素可以是数字,也可以是 另一个括号,请实现一个算法消除嵌套的括号,比如把上面的表达式变成:(1,2,3,4,5,6,7), 如果表达式有误请报错。 */ /************************************************************************/ #include <stdio.h> #include <iostream> using namespace std; const int NUM = 100; char stack[NUM]; char str[NUM]; /** 消除内嵌括号 **/ void remove_inline_brackets(char *str) { char tem[NUM]; memset(tem,0,sizeof(tem)); int top = -1,i=0,index=0; while(str[i] != '