1024. 科学计数法 (20)
来源:互联网 发布:乐视无线显示网络异常 编辑:程序博客网 时间:2024/05/16 02:26
题目链接:https://www.patest.cn/contests/pat-b-practise/1024
1024. 科学计数法 (20)
时间限制
100 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
HOU, Qiming
科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式[+-][1-9]"."[0-9]+E[+-][0-9]+,即数字的整数部分只有1位,小数部分至少有1位,该数字及其指数部分的正负号即使对正数也必定明确给出。
现以科学计数法的格式给出实数A,请编写程序按普通数字表示法输出A,并保证所有有效位都被保留。
输入格式:
每个输入包含1个测试用例,即一个以科学计数法表示的实数A。该数字的存储长度不超过9999字节,且其指数的绝对值不超过9999。
输出格式:
对每个测试用例,在一行中按普通数字表示法输出A,并保证所有有效位都被保留,包括末尾的0。
输入样例1:+1.23400E-03输出样例1:
0.00123400输入样例2:
-1.2E+10输出样例2:
-12000000000
#include <iostream>#include <string>#include <sstream>using namespace std;string copy(string c, int count) {string s;while (count-- > 0)s.append(c);return s;}int main() {string st, tmps, s; cin >> st;int i, len = st.length(), e = 0, indexE = 0, indexdot = 0;if (st[0] == '-') s.append("-");indexE = st.find_first_of('E');indexdot = st.find_first_of('.');tmps = st.substr(indexE + 1);stringstream sstr(tmps);//字符串转换为数值sstr >> e; //即从sstr中提取数据if (e < 0) {e = -e;s.append("0."); tmps = copy("0", e - 1);s.append(tmps);s.append(st.substr(indexdot - 1, 1));//加点前的一个数字s.append(st.substr(indexdot + 1, indexE - indexdot - 1));}else if (e == 0) {s.append(st.substr(indexdot - 1, indexE - indexdot + 1));}else {s.append(st.substr(indexdot - 1, 1));//取点前一个数字int dist = indexE - indexdot;if (e < dist) {s.append(st.substr(indexdot + 1, e));if (dist - 1 - e > 0) {//1.010E2情形s.append(".");//加点后还要加子串s.append(st.substr(indexdot + e + 1, dist - 1 - e));}}else {s.append(st.substr(indexdot + 1, dist - 1));tmps = copy("0", e - dist + 1);s.append(tmps);}}cout << s << endl;return 0;}
阅读全文
0 0
- 1024. 科学计数法 (20)
- 1024. 科学计数法 (20)
- 1024. 科学计数法 (20)
- 1024. 科学计数法 (20)
- 1024. 科学计数法 (20)
- 1024. 科学计数法 (20)
- 1024. 科学计数法 (20)
- 1024. 科学计数法 (20)
- 1024. 科学计数法 (20)
- 1024. 科学计数法 (20)
- 1024. 科学计数法 (20)
- 1024. 科学计数法 (20)
- 1024. 科学计数法 (20)
- 1024. 科学计数法 (20)
- 1024. 科学计数法 (20)
- 1024. 科学计数法 (20)
- 1024. 科学计数法 (20)
- 1024. 科学计数法 (20)
- SpringMVC原理及配置详解
- HDU 1325 Is It A Tree?
- Python发送Http请求时,中文乱码问题的解决方法
- UVa 113|Power of Cryptography|牛顿迭代法|pow函数的应用
- 20171005memo
- 1024. 科学计数法 (20)
- 网络编程_高级函数
- JS动画函数的封装
- Bzoj 1647: Fliptile 翻格子游戏 状态压缩
- 捕捉Win32窗口操作
- 【专题】区间dp
- Java虚拟机
- SpringMVC Controller 介绍
- 循环队列的顺序存储与链队列