题目链接:http://poj.org/problem?id=1686
思路分析:该问题为表达式求值问题,对于字母使用浮点数替换即可,因为输入中的数字只能是单个digit。
代码如下:
#include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <cstdlib> #include <string> using namespace std; const int MAX_N = 100; const double factor = 1.1; double number[MAX_N]; char str[MAX_N]; int len, pos; double Expression( ); double Term( ); double Factor( ); void InputExpression( ) { int i = 0; pos = 0; string str_in; getline(cin, str_in); for (i = 0, len = 0; i < str_in.length( ); ++i, ++len) str[len] = str_in[i]; str[len] = '