khushbuparakh
BAN USER- 0of 0 votes
AnswersGiven an arithmetic expression, write a program to find the value of the expression. Only binary operations that are allowed are +,-,*,/. Also assume that all parentheses are well matched.
- khushbuparakh in India
Note that the use of eval() is forbidden
Input format :There is a single positive integer T on the first line of input . It stands for the number of expressions to follow.
Next T lines followed by expression
Output format : For each expression print the value of expression
3
19 + 12 / 4 - ((4 - 7) * 3 / 1)
1 + (2 - 3) * 4 + 5 - 6 * 8 - (18 * 12 * 13) - (11 / (5 + 2 + 4))
((2 + 4) / 3 - 2 + 1)
Output:
31
-2855
1| Report Duplicate | Flag | PURGE
Amazon Android Engineer Math & Computation
{"errors":["/usercode/file.cpp: In member function 'void Parser::Program(std::vector<int>&)':\n/usercode/file.cpp:35:17: error: 'class std::vector<int>' has no member named 'emplace_back'\n res.emplace_back(eres);\n ^\n/usercode/file.cpp: In function 'int main()':\n/usercode/file.cpp:212:15: error: 'i' does not name a type\n for (auto i : Parser(s1).Parse()) cout << i << endl;\n ^\n/usercode/file.cpp:214:5: error: expected ';' before 'cout'\n cout << endl << endl << \"test string s2:\" << endl << s2 << endl << endl;\n ^\n/usercode/file.cpp:215:5: error: expected primary-expression before 'for'\n for (auto i : Parser(s2).Parse()) cout << i << endl;\n ^\n/usercode/file.cpp:215:5: error: expected ')' before 'for'\n/usercode/file.cpp:215:15: error: 'i' does not name a type\n for (auto i : Parser(s2).Parse()) cout << i << endl;\n ^\n/usercode/file.cpp:217:1: error: expected ';' before '}' token\n }\n ^\n/usercode/file.cpp:217:1: error: expected primary-expression before '}' token\n/usercode/file.cpp:217:1: error: expected ';' before '}' token\n/usercode/file.cpp:217:1: error: expected primary-expression before '}' token\n/usercode/file.cpp:217:1: error: expected ')' before '}' token\n/usercode/file.cpp:217:1: error: expected primary-expression before '}' token\n/usercode/file.cpp:217:1: error: expected ';' before '}' token\n","/usercode/file.cpp: In member function 'void Parser::Program(std::vector<int>&)':\n/usercode/file.cpp:35:17: error: 'class std::vector<int>' has no member named 'emplace_back'\n res.emplace_back(eres);\n ^\n/usercode/file.cpp: In function 'int main()':\n/usercode/file.cpp:212:15: error: 'i' does not name a type\n for (auto i : Parser(s1).Parse()) cout << i << endl;\n ^\n/usercode/file.cpp:214:5: error: expected ';' before 'cout'\n cout << endl << endl << \"test string s2:\" << endl << s2 << endl << endl;\n ^\n/usercode/file.cpp:215:5: error: expected primary-expression before 'for'\n for (auto i : Parser(s2).Parse()) cout << i << endl;\n ^\n/usercode/file.cpp:215:5: error: expected ')' before 'for'\n/usercode/file.cpp:215:15: error: 'i' does not name a type\n for (auto i : Parser(s2).Parse()) cout << i << endl;\n ^\n/usercode/file.cpp:217:1: error: expected ';' before '}' token\n }\n ^\n/usercode/file.cpp:217:1: error: expected primary-expression before '}' token\n/usercode/file.cpp:217:1: error: expected ';' before '}' token\n/usercode/file.cpp:217:1: error: expected primary-expression before '}' token\n/usercode/file.cpp:217:1: error: expected ')' before '}' token\n/usercode/file.cpp:217:1: error: expected primary-expression before '}' token\n/usercode/file.cpp:217:1: error: expected ';' before '}' token\n"],"all_passed":false,"time":
- khushbuparakh July 04, 2016error: two or more data types in declaration of āiā
for (auto int i : Parser(s1).Parse()) cout << i << endl;
^
- khushbuparakh July 04, 2016
- khushbuparakh August 18, 2016