九度:1019<模拟>
来源:互联网 发布:淘宝无法查询物流信息 编辑:程序博客网 时间:2024/05/15 04:17
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 205using namespace std;int main(){#ifdef ONLINE_JUDGE#elsefreopen("E:\\in.txt", "r" , stdin);#endifdouble 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 lineint 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);}//whilereturn 0;}
0 0
- 九度:1019<模拟>
- 【九度OJ】1002【模拟】
- 【九度OJ】1010【模拟】
- 【九度OJ】1022【模拟】
- 【九度OJ】1036【模拟】
- 【九度OJ】1018【模拟】
- 【九度OJ】1048【模拟】
- 【九度OJ】1021【模拟】
- 【九度OJ】1032【模拟】
- 【九度OJ】1013【模拟】
- 九度OJ 1014 排名 (模拟)
- 九度OJ 1177 查找 (模拟)
- 九度OJ 1179 阶乘(模拟)
- 九度OJ 打印日期 (模拟)
- 九度 1076 N的阶乘(模拟)
- 九度 1083:特殊乘法(模拟)
- 模拟电路设计九阶段
- 【九度OJ】1015【模拟】【A+B系列2006】
- iOS 在UILabel显示不同的字体和颜色
- 三重背包
- BOM之navigator对象
- 用Resteasy实现restful web service
- 采用aidl挂断电话
- 九度:1019<模拟>
- File类的部分常用方法
- C++函数重载详解
- 黑马程序员-第九天(包)
- Java中的Swing
- socket网络编程
- Scanner 与Console的用法和异同点
- 九度:1020<最小长方形>
- cocos2d-x iOS和Android同步开发 手机设备适配问题解决