Mike is a middle school teacher.He is teaching mathematics.After each chapter,he always arranges some homework to his students.In this chapter,he will ask his students to calculate the value of some expressions.There are many brackets in these expres

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/25 02:51:25
Mikeisamiddleschoolteacher.Heisteachingmathematics.Aftereachchapter,healwaysarrangessomehomeworktohi

Mike is a middle school teacher.He is teaching mathematics.After each chapter,he always arranges some homework to his students.In this chapter,he will ask his students to calculate the value of some expressions.There are many brackets in these expres
Mike is a middle school teacher.He is teaching mathematics.After each chapter,he always arranges some homework to his students.In this chapter,he will ask his students to calculate the value of some expressions.There are many brackets in these expressions.Sometimes it is very difficult to find whether these brackets are match or not.In other time,it’s difficult to find whether the brackets are at the right positions.Please write a program to help him to check these expressions.
Input
Input includes n+1 lines,the first of these lines is an integer number n,which implies that there are n expressions to be checked.Each line represents one expression which includes double number,+,-,*,/ operator or (,) brackets.
Output
For each expression,output one word ‘Legal’ or ‘Illegal’.
Sample Input
2
2.3+(4.5+3.678)/3.4*2.5+(3.4+(4.5-(2.3)*3)
4.5+(4.2324*3.8)-3.4*(1.5-(3.4*(5.6/(3.6-(2.8)))))
Sample Output
Illegal
Legal
我的代码:
#include
#include
#include
using namespace std;
int main()
{
int t,i=0;
char ch;
cin>>t;
getchar();
while(t--)
{
stackstack1;
while(1)
{
scanf("%c",&ch);
switch(ch)
{
case '(':
stack1.push(ch);
break;
case ')':
stack1.pop();
break;
}
if(ch=='\n')
{
if(stack1.empty())
cout

Mike is a middle school teacher.He is teaching mathematics.After each chapter,he always arranges some homework to his students.In this chapter,he will ask his students to calculate the value of some expressions.There are many brackets in these expres
注意看题目,有两种情况不合法:
1)Sometimes it is very difficult to find whether these brackets are match or not.
2)In other time, it’s difficult to find whether the brackets are at the right positions.
你的代码忽略了第二条,只判断了括号是否匹配,没有判断括号是否放在合适的位置.
比如你试试这个:
3(2)
显然是个不合法表达式,不过你的代码会认为它合法.

Jack is a student and studise at the No.2 Middle School.( ) It was the same with MikeSo it is with Mike So is Mike So dose Mike Jack is a student and studies at the no.2 middle school.__.A so it is with Mike B so is Mike该选哪个 Jack is a student and studies at the No.1 Middle School.___.A.It was the same with Mike B.So it is with Mike C.So is Mike D.So does Mike Jack is a student and studies at the No.2 Middle School.________.A.It was the same with Mike B.So it is with Mike C.So is Mike D.So does Mike Jack is a student and studies at the No. 2 Middle School. _____.A. It was the same with Mike B.So it is with Mike C. So is Mike D. So does Mike 帮忙分析下咯. Jack is a student and studies at the No.I Middle School._____A.It was the same with Mike B.so it is with Mike c.So is Mike D.So does Mike 一定选B,给理由吧 Jack is a student and studies at the No.I Middle School._____A.It was the same with Mike B.so it is with Mike c.So is Mike D.So does Mike There is a middle 分析一道英语题目Jack is a student and studies at the NO.2 Middle school.______________.A.It was the same with Mike B.So it is with Mike C.So is Mike D.So does Mike 选B,WHY? 14.Jack is a student and studies at the No.2 Middle School._____.A.It was the same with Mike B.So it is with Mike C.So is Mike D.So does Mike选哪个 为什么 能解释下为什么吗 thank you~ Mike is a famous player My name is Mike Green.l come from England.l study in a middle school in London.My father works i-Mike is an _______boy He is a middle school ______.His father is a ______His mother__________go to work Jobn doesn't go to school on _________and________ 将mike is a careful boy.改为感叹句[ ] [ ] mike is! 请根据对话内容,填入适当的句子完成对话Anna:Good morning!( Bob:yes,i am.( Anna:my name is Anna Wilson.call me AnnaBob:( Anna:A-N-N-A,Anna,W-I-L-S-O-N,wilsonBob:thank you.( )Anna:Nice to meet you .mike!mike:( welcome to our sch 1.( )____number of tourists visit Wuxi every day.___ number of the tourists is getting larger and larger.A .A ;The B .The;A C .A ;A D .The ;The2.( ) My mother is __ too busy to go shopping today.A .far B .very C ,so D.quite3.( ) ___is No ,1MIddle Sch she is a student____NO.2 Middle School he is a( ) middle school student she is in a middle school