输入一行表达式,判断该表达式中的括号是否匹配.括号要求符合C++表达式的要求.若左括号与右括号匹配,则

学习 时间:2026-04-06 18:16:08 阅读:8574
输入一行表达式,判断该表达式中的括号是否匹配.括号要求符合C++表达式的要求.若左括号与右括号匹配,则

最佳回答

优雅的大炮

如意的西牛

2026-04-06 18:16:08

#include using namespace std;#define MAX_SIZE 50typedef struct {int stack[MAX_SIZE];int top;}Stack;int main(){Stack st;st。top=-1;char ch;bool flag=false;while (cin>>ch){switch (ch){case '(':st。stack[++st。top]=ch;break;case ')':if (st。stack[st。top]=='('){st。top--;break;}else {cout 再问: 问题本身是这样的:::::谢谢!!! 输入一行表达式,判断该表达式中的括号是否匹配。括号要求符合C++表达式的要求。若左括号与右括号匹配,则输出”correct”; 否则输出“not correct”。 如: (3+(3-2))*5 correct (2+3))*4 not correct )2+3( not correct Input 输入一行表达式。(字符个数不超过100个) Output 若左括号与右括号匹配,则输出”correct”; 否则输出“not correct”。 再答: #include using namespace std; #define MAX_SIZE 50 typedef struct { int stack[MAX_SIZE]; int top; }Stack; int main() { Stack st; st。top=-1; char ch; bool flag=false; while (cin。get(ch)&&ch!='\n') { switch (ch) { case '(': st。stack[++st。top]=ch; break; case ')': if (st。stack[st。top]=='(') { st。top--; break; } else { //cout

最新回答共有2条回答

  • 激情的口红
    回复
    2026-04-06 18:16:08

    #include using namespace std;#define MAX_SIZE 50typedef struct {int stack[MAX_SIZE];int top;}Stack;int main(){Stack st;st。top=-1;char ch;bool flag=false;while (cin>>ch){switch (ch){case '(':st。stack[++st。top]=ch;break;case ')':if (st。stack[st。top]=='('){st。top--;break;}else {cout 再问: 问题本身是这样的:::::谢谢!!! 输入一行表达式,判断该表达式中的括号是否匹配。括号要求符合C++表达式的要求。若左括号与右括号匹配,则输出”correct”; 否则输出“not correct”。 如: (3+(3-2))*5 correct (2+3))*4 not correct )2+3( not correct Input 输入一行表达式。(字符个数不超过100个) Output 若左括号与右括号匹配,则输出”correct”; 否则输出“not correct”。 再答: #include using namespace std; #define MAX_SIZE 50 typedef struct { int stack[MAX_SIZE]; int top; }Stack; int main() { Stack st; st。top=-1; char ch; bool flag=false; while (cin。get(ch)&&ch!='\n') { switch (ch) { case '(': st。stack[++st。top]=ch; break; case ')': if (st。stack[st。top]=='(') { st。top--; break; } else { //cout

上一篇 #include #include void main() {float a,b,c,d; float x0,x1,x2

下一篇 Mr Li very busy tody ,so he has no time (paly)basketball wit