首页 > 试题广场 >

简单计算器

[编程题]简单计算器
  • 热度指数:24153 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
    读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值。

输入描述:
    测试输入包含若干测试用例,每个测试用例占一行,每行不超过200个字符,整数和运算符之间用一个空格分隔。没有非法表达式。当一行中只有0时输入结束,相应的结果不要输出。


输出描述:
    对每个测试用例输出1行,即该表达式的值,精确到小数点后2位。
示例1

输入

1 + 2
4 + 2 * 5 - 7 / 11
0

输出

3.00
13.36
头像 薇薇啵啵
发表于 2020-04-05 17:55:09
/* * 《算法笔记》p245 第七章 提高篇(1)————数据结构专题(1) * 7.1 栈的应用:【Codeup 1918】简单计算器 * http://codeup.cn/problem.php?cid=100000605&pid=0 * 题目描述:读入一个只包含 +, -, 展开全文
头像 诗云panther
发表于 2021-08-20 12:10:30
//全排列的内部实现 include include include using namespace std; const int maxn = 7; char site[maxn] = {0};string str; void solve(int num){ if(num == str.le 展开全文
头像 牛客440904392号
发表于 2024-10-05 22:42:31
print('%.2f' % eval(input()))
头像 yyer
发表于 2023-03-03 20:33:05
#include <iostream> #include <stack> using namespace std; /* 表示一个运算符的类型以及优先级 栈内:+,- (优先级:3) *,/(优先级:5) 栈外:+,- (优先级:2) *,/(优先级:4) * 展开全文
头像 ALJT
发表于 2022-04-19 16:44:24
简单的题还是写了那么多代码。。。 该题注意2个地方: 字符串输入,sstream 结果的输出,中途用stod将string转为double,保证精度 #include <iostream> #include <stack> #include <string> 展开全文
头像 渺小小螃蟹
发表于 2021-05-13 14:06:28
#include<iostream> #include<string> #include<stack> #include<cctype> using namespace std; //优先级顺序#,$,+-,*/ int priority(char 展开全文
头像 牛客568792594号
发表于 2024-03-04 10:31:18
#include <bits/stdc++.h> using namespace std; stack<char> op; stack<double> num; unordered_map<char, int> pr; void eval(){ 展开全文
头像 aaaawei
发表于 2021-01-16 16:53:05
对于输入字符串要单独考虑 对于优先级函数返回值只有几种情况而没有考虑所以情况编译器会报错!#include<cstdio>#include<iostream>#include<stack>#include<string>using namespace 展开全文
头像 在春招的王者很想去西藏旅游
发表于 2024-03-15 14:02:01
#include <bits/stdc++.h> #include <cstddef> #include <cstdio> #include <stack> #include <string> using namespace std; i 展开全文
头像 GoodLunatic
发表于 2024-09-03 14:35:35
#include <iostream> #include <stack> #include <string> using namespace std; stack<double> num; stack<char> op; string p 展开全文