SPOJ ARITH2
来源:互联网 发布:盒子直播平台源码 编辑:程序博客网 时间:2024/05/17 02:39
//http://www.spoj.com/problems/ARITH2/#include <iostream>#include <queue>#include <cstdlib>using namespace std;int main() {int t;cin >> t;queue<string> numbers;queue<string> operations;long result = 0;bool first = true;while (t-- >0) {string item;cin >> item;operations.empty();numbers.empty();result = 0;first = true;while (item != "=") {if (item == "+" ||item == "-" ||item == "*" ||item == "/") {operations.push(item);} else {numbers.push(item);}cin >> item;}if (item == "=") {while (operations.size() != 0) {string op = operations.front();operations.pop();string opdata1, opdata2;long d1, d2;if (first) {opdata1 = numbers.front();numbers.pop();opdata2 = numbers.front();numbers.pop();d1 = atol(opdata1.c_str());d2 = atol(opdata2.c_str());first = false;} else {d1 = result;opdata2 = numbers.front();numbers.pop();d2 = atol(opdata2.c_str());}if (op == "+") {result = d1 + d2;} else if (op == "-") {result = d1 - d2;} else if (op == "*") {result = d1 * d2;} else {result = d1 / d2;}}cout << result << endl;}}}
0 0
- SPOJ ARITH2
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- 重新开始打理博客了
- TopCoder SRM 144 DIV2(550-point)
- 回归2013,展望2014
- Android用root切换飞行模式
- setchecked方法会触发OnCheckedChangeListener
- SPOJ ARITH2
- 字符串问题3:是否是有效数字
- UML之状态图
- MySQL配置Master-Slave
- Indexing and Searching on a Hadoop Distributed File System (如何在HDFS文件上建索引)
- 十八.银行业务调度系统
- 基础的seekbar写法
- Ubuntu12.04配置CUDA编程环境
- hdu1164