九度:1019<模拟>
2014-03-02 23:09
302 查看
http://ac.jobdu.com/problem.php?pid=1019
// 浙大2006年机试 // 九度:1019 // 题目:简单计算器 // // 第一次做错了,想了好久才发现自己的错误。 // 第一次中,每次都是读取字符,也就意味着, // 程序只能计算个位数的数据。测试自己写的 // case 也都正确,所以哎呀! // // 第二次更新了策略,第一次读取一个浮点数, // 接下来每次读取一个字符,如果是空格在读 // 取一个字符和一个浮点数,空格说明不是结 // 束。 // // #include <stdio.h> #include <cctype> #include <cmath> #include <cstring> #include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <stack> #define SIZE 205 using namespace std; int main(){ #ifdef ONLINE_JUDGE #else freopen("E:\\in.txt", "r" , stdin); #endif double x; while(scanf("%lf", &x) != EOF && x ) { double qn[SIZE]; char qs[SIZE]; int pos = 0; char c; qn[pos] = x; while(scanf("%c", &c) && c != '\n') { if(c == ' ') scanf("%c %lf", &c, &x); if(c == '+' || c == '-') { qs[pos++] = c; qn[pos] = x; } else if(c == '*') { qn[pos] *= x; } else { qn[pos] /= x; } }//read a line int len=pos; double ans=qn[0]; for(int i=0; i<len; i++) { c = qs[i]; if(c == '+') { ans += qn[i+1]; }else{ ans -= qn[i+1]; } } printf("%.2lf\n", ans); }//while return 0; }
相关文章推荐
- 九度:1019<图的连通性>
- 九度:1014<排序>
- 九度:1015<A+B>
- 九度:1017<并查集><Kruskal><MST>
- 九度:1016<火星A+B>
- 九度:1009<二叉搜索树><二叉排序树><建立二叉树><遍历>
- 九度:1024<并查集>
- 九度:1018<Hash>
- 九度:1201<二叉排序树><建立,遍历>
- 九度:1008<最短路径>
- 九度:1028<并查集>
- 九度:1029<魔咒词典><排序查找>
- 九度:1162<I wanna go home><最短路径>
- 九度:1448<拓扑排序>
- <九度 OJ>题目1112:拦截导弹
- 九度:1027<欧拉回路><搜索>
- 九度:1449<拓扑排序><DAG>
- <九度 OJ>题目1545:奇怪的连通图
- 九度:1020<最小长方形>
- 九度:1026<A+B>