首页 > 试题广场 >

四则运算

[编程题]四则运算
  • 热度指数:135856 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
\hspace{15pt}对于输入的表达式,保证其形式合法、计算过程中全程合法、计算过程中不需要使用到实数、结果 {\rm ans} 满足 -10^3 \leqq {\rm ans} \leqq 10^3 。直接输出计算结果。

\hspace{15pt}保证表达式字符串由 0-9 的数字、加法 \texttt{`+'} 、减法 \texttt{`-'} 、乘法 \texttt{`*'} 、除法 \texttt{`/'} 、小括号 \texttt{`('},\texttt{`)'} 、中括号 \texttt{`['},\texttt{`]'} 、大括号 \texttt{`\{'},\texttt{`\}'} 组成,且运算符之间没有空格。

输入描述:
\hspace{15pt}输入一个长度为 1 \leqq {\rm len}(s) \leqq 10^3 、由题面所述符号构成的字符串,代表一个表达式。


输出描述:
\hspace{15pt}输出一个整数 \rm ans ,代表计算的答案。满足 -10^3 \leqq {\rm ans} \leqq 10^3
示例1

输入

3+2*{1+2*[-4/(8-6)+7]}

输出

25

说明

\hspace{15pt}在这个样例中,计算过程为:\begin{array}{ll}<br />& 3+2\times\big\{1+2\times{[-4 \div (8-6)+7]}\big\} \\<br />= & 3 + 2 \times \big\{1 + 2 \times [-4 \div {\color{orange}{\bf2}} + 7]\big\} \\<br />= & 3 + 2 \times \big\{1 + 2 \times [{\color{orange}{\bf{-2}}} + 7]\big\} \\<br />= & 3 + 2 \times \big\{1 + 2 \times {\color{orange}{\bf5}}\big\} \\<br />= & 3 + 2 \times \big\{1 + {\color{orange}{\bf10}}\big\} \\<br />= & 3 + 2 \times {\color{orange}{\bf11}} \\<br />= & 3 + {\color{orange}{\bf22}} \\<br />= & {\color{orange}{\bf25}}<br />\end{array}

这道题你会答吗?花几分钟告诉大家答案吧!

问题信息

难度:
0条回答 49814浏览

热门推荐

通过挑战的用户

查看代码
四则运算