谦虚

10185101150 edited 5 年,1 月前

include

include

include

define max 100000

char a[max]={‘\0’};
char b[max]={‘\0’};
class stack
{public :
stack();
void push (const double &item);
void pop ();
double top();
bool is_empty();
void reverse();
void clear();
private:
int count;
double entry[1000];
};
stack::stack()
{count=0;
}
void stack::clear()
{
count=0;
}
void stack::reverse()
{int i;
double a[1000]={0};
for (i=0;i<count;i++)
a[i]=entry[count-1-i];
for (i=0;i<count;i++)
entry[i]=a[i];
}
void stack::push(const double &item)
{entry[count]=item;
count++;
}
void stack::pop()
{
count–;
}
double stack::top()
{
return entry[count-1];
}
bool stack::is_empty()
{
if (count==0)
return true;
return false;
}
double power(double a,int len)
{int i;
for (i=0;i<len;i++)
a=a/10;
return a;
}
int main()
{char a[1000];
int i,j;
int n;
stack cjn,ckn;
scanf(“%d”,&n);
getchar();
for (j=0;j<n;j++)
{
gets(a);
int len=strlen(a);
for (i=0;i=‘0’ && a[i]<=‘9’)||a[i]==’.’)
{if (a[i]==’.’)
{pan=i;
i++;
continue;
}
if (pan==0)
result=result*10+a[i]-48;
else
result=result+power(a[i]-48,i-pan);

i++;
}
cjn.push(result);

}

}
}//输入
cjn.reverse();
while (!ckn.is_empty())
{double a,b;
a=cjn.top();
cjn.pop();
b=cjn.top();
cjn.pop();
int op=ckn.top();
switch (op)
{case ‘+’:cjn.push(a+b);break;
case ‘-‘:cjn.push(a-b);break;
case ‘‘:cjn.push(ab);break;
case ‘/’:cjn.push(a/b);break;
}
ckn.pop();
}
printf(“case #%d:\n”,j);
printf(“%lf\n”,cjn.top());
cjn.clear();
ckn.clear();
}
return 0;
}

Comments