数据结构实验之栈三:后缀式求值
来源:互联网 发布:cube escape 知乎 编辑:程序博客网 时间:2024/04/30 05:55
Time Limit: 1000MS Memory limit: 65536K
题目描述
输入
输出
示例输入
59*684/-3*+#
示例输出
57
提示
来源
示例程序
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<stack>
using namespace std;
int main()
{
int i;
char str[110];
scanf("%s",str);
stack<int>q;
for(i=0;str[i]!='#';i++)
{
if(str[i]>='0'&&str[i]<='9')
q.push(str[i]-48);
else
{
if(str[i]=='+')
{
int a=q.top();
q.pop();
int b=q.top();
q.pop();
int c=a+b;
q.push(c);
}
if(str[i]=='-')
{
int a=q.top();
q.pop();
int b=q.top();
q.pop();
int c=b-a;
q.push(c);
}
if(str[i]=='*')
{
int a=q.top();
q.pop();
int b=q.top();
q.pop();
int c=a*b;
q.push(c);
}
if(str[i]=='/')
{
int a=q.top();
q.pop();
int b=q.top();
q.pop();
int c=b/a;
q.push(c);
}
}
}
printf("%d\n",q.top());
return 0;
}
- SDUT2133数据结构实验之栈三:后缀式求值(栈)
- 数据结构实验之栈三:后缀式求值
- 数据结构实验之栈三:后缀式求值
- 数据结构实验之栈三:后缀式求值
- 数据结构实验之栈三:后缀式求值
- 数据结构实验之栈三:后缀式求值
- SDUT 2133 数据结构实验之栈三:后缀式求值
- 数据结构实验之栈三:后缀式求值
- 数据结构实验之栈三:后缀式求值
- 数据结构实验之栈三:后缀式求值
- 数据结构实验之栈三:后缀式求值
- SDUT 2133 数据结构实验之栈三:后缀式求值
- 数据结构实验之栈三:后缀式求值
- 数据结构实验之栈三:后缀式求值
- 数据结构实验之栈三:后缀式求值
- SDUT 3133 数据结构实验之栈三:后缀式求值
- 数据结构实验之栈三:后缀式求值 SDUT 2133
- 数据结构实验之栈三:后缀式求值
- 问题:jquery中的.on() .one() .off()函数
- Light-oj 1078 (除法模拟)
- Educational Codeforces Round 1 C - Nearest vectors
- python入门神图
- android开发步步为营之108:下载断点续传
- 数据结构实验之栈三:后缀式求值
- 欢迎使用CSDN-markdown编辑器
- C#控制台 输出hello world之 在main函数下使用console.writeline
- C语言文件操作函数
- XML解析之pull解析
- Android自定义View实战---圆盘温度计
- 多线程编程入门(7):线程范围内的共享变量
- 排序算法 之 希尔排序ShellSort
- 匈牙利算法(膜拜大神orz)