算数表达式求值
2015-04-11 16:32
239 查看
不带括号时,直接遍历一次,再累和
#include <stdio.h> #include <string.h> int main(){ char ch; int a[200], temp; while(scanf("%d", &a[0]) != EOF){ int i = 0; while(scanf("%c", &ch) != EOF && ch != '\n'){ scanf("%d", &temp); if(ch == '+') a[++i] = temp; else if(ch == '-') a[++i] = -temp; else if(ch == '*') a[i] *= temp; else if(ch == '/') a[i] /= temp; } for(int j = 1; j <= i; ++j) a[0] += a[j]; printf("%d\n", a[0]); } return 0; }
相关文章推荐
- 算数表达式求值
- 算数表达式求值
- Java字符串算数表达式求值
- Dijkstra双栈算数表达式求值算法的过程与分析
- C语言 算数表达式求值(顺序栈应用实例)
- 简单算数表达式求值
- 运用栈对算数表达式求值
- QT算数表达式求值
- 算数表达式求值(中缀表达式转后缀表达式并求值)
- 算数表达式求值
- 栈的运用(算数表达式求值的算符优先算法 十以内简单版)
- 算法(第四版) Dijkstra 算数表达式求值算法-双栈
- 栈3-算数表达式求值
- 算数表达式求值
- CDOJ 1074 秋实大哥搞算数(栈_表达式求值)
- 算数表达式求值C++实现
- 算数表达式求值(C语言)
- C++ 实现 算数表达式求值
- Dijkstra 的双栈算数表达式求值算法的学习
- 2015 UESTC 数据结构专题N题 秋实大哥搞算数 表达式求值/栈