finish
#include<iostream>
#include<cctype>
#include<cmath>
#include<stdio.h>
#include<string.h>
using namespace std;
void badshow();
void highlevel(const char*);
double result(double a,double b,char c);
bool done(const char*,int);
void suanfa(const char*);
void init(const char *);
int top=-1;//for level
int top1=-1;//for sign
int top2=0;//for number
double* number;//store number
char* sign;//store sign
static int i=-1;//piont to the shizi array
int* level;//store the level
int mark;//the current level
int* aim;
int first;
int wrong;//
int main()
{
char *shizi;
wrong=0;
first=0;
mark=25;//>0
number=new double[100];
sign=new char[20];
level=new int[20];
aim=new int[10];
shizi=new char[100];
level[0]=-4;
//cin.unsetf(ios::skipws);
while(cin>>shizi && shizi!="quit")
{
suanfa(shizi);
if(wrong!=1) break;
init(shizi);
}
cout<<"the final result is "<<number[0];
return 0;
}
void highlevel(const char* shizi)
{
if(wrong==1) return;
if(mark==-1 && top1!=-1)
{
badshow();
return;
}
double a,b;
if(mark==0)
if(sign[top]!=shizi[i] && (top==0 || top==-1))
{
cout<<"The position of "<<i+1<<" is wrong."<<endl;
wrong=1;
return;
}
else if(level[top]==0)
{
top--;
top1--;
return;
}
if(top==-1)
{
level[++top]=mark;
sign[top]=shizi[i];
}
else if(mark<=level[top])
{
if(top>=0)
{
a=number[top2--];
number[top2+1]=0.0;
b=number[top2];
//cout<<"After the functions b is "<<b<<",a is "<<a<<".And there are "<<top2+1<<" numbers in array currently"<<endl;//check the problem
number[top2]=result(b,a,sign[top--]);
if(mark==-1 && top2==0) return;
}
highlevel(shizi);
}
else
{
level[++top]=mark;
sign[top]=shizi[i];
}
return;
}
最后修改于2008-11-24 17:51:00