#include
using namespace std;
const int InitSize=100;
const int IncreastSize=10;
template
class SqStack {
private:
datatype *base;
datatype *top;
int stacksize;
public:
SqStack();
void DestroyStack();
void ClearStack();
int StackLength();
bool IsEmpty();
bool GetTop(datatype &e);
bool Pop(datatype &e);
bool Push(datatype e);
};
template
SqStack
{
base=new datatype[InitSize];
if(!base)exit(1);
top=base;
stacksize=InitSize;
}
template
void SqStack
{
delete[] base;
base=top=NULL;
stacksize=0;
}
template
void SqStack
{top=base;
}
template
int SqStack
{return top-base;
}
template
bool SqStack
{
if(top==base)
return fasle;
else return true;
}
template
bool SqStack
{
if(top==base)
return false;
e=*(top-1);
return true;
}
template
bool SqStack
{
if(top==base)
return false;
e=*(top-1);
top--;
return true;
}
template
bool SqStack
{
if(top-base>=stacksize)
{
base=(datatype *)realloc( base , (stacksize+IncreastSize)*sizeof(int) );
if(!base)exit(1);
top=base+stacksize;
stacksize+=IncreastSize;
}
*(top)=e;
top++;
return true;
}
int com(char m,char t)
{
if(t=='(') return -1;
else if(t==')')
{if(m=='+'||m=='-'||m=='*'||m=='/') return 1;
else if(m=='(') return 0;
else return -2;
}
else if(t=='*'||t=='/')
{if(m=='+'||m=='-'||m=='#'||m=='(') return -1;
else return 1;
}
else if(t=='+'||t=='-')
{if(m=='#'||m=='(') return -1;
else return 1;
}
else
{if(m=='#')return 0;
else if(m=='+'||m=='-'||m=='*'||m=='/') return 1;
else return -2;
}
}
void main()
{
SqStack
SqStack
char t,m;
double result,flag=1;
op.Push('#');
t=getchar();
while(true){
if(t>='0'&&t<='9')
{double s=0;
s=s*10+t-'0';
t=getchar();
while(t>='0'&&t<='9' )
{s=s*10+t-'0';
t=getchar();
}
re.Push(s);
}
else if(t=='+'||t=='-'||t=='*'||t=='/'||t=='('||t==')'||t=='\n')
{ op.GetTop(m);
while(com(m,t)==1 )
{double x1,x2;
op.Pop(m);
if(re.Pop(x2)&&re.Pop(x1))
{if(m=='+') re.Push(x1+x2);
else if(m=='-') re.Push(x1-x2);
else if(m=='*') re.Push(x1*x2);
else if(m=='/') {if(x2!=0)re.Push(x1/x2); else flag=0;}
}
else flag=0;
op.GetTop(m);
}
if(com(m,t)==-1)
op.Push(t);
else if(com(m,t)==0)
op.Pop(m);
else flag=0;
if(!op.GetTop(m)) break;
t=getchar();
}
else t=getchar();
}
if(re.GetTop(result)&&flag)
cout<
}
你这分数也太少了呗?至少的要一天才能搞定的!
这个分低了,确实。。。。