PAT甲级——A1073 Scientific Notation
Scientific notation is the way that scientists easily handle very large numbers or very small numbers. The notation matches the regular expression [+-][1-9].[0-9]+E[+-][0-9]+ which means that the integer portion has exactly one digit, there is at least one digit in the fractional portion, and the number and its exponent's signs are always provided even when they are positive.
Now given a real number A in scientific notation, you are supposed to print A in the conventional notation while keeping all the significant figures.
Input Specification:
Each input contains one test case. For each case, there is one line containing the real number A in scientific notation. The number is no more than 9999 bytes in length and the exponent's absolute value is no more than 9999.
Output Specification:
For each test case, print in one line the input number A in the conventional notation, with all the significant figures kept, including trailing zeros.
Sample Input 1:
+1.23400E-03
Sample Output 1:
0.00123400
Sample Input 2:
-1.2E+10
Sample Output 2:
-12000000000
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str, f1, num1, num2, f2, num3, res = "";
cin >> str;
int nDot, E, Exp = ;
f1 = str[];
nDot = str.find('.');
num1 = str[nDot - ];//第一位数字
E = str.find('E');
num2.assign(str.begin() + nDot + , str.begin() + E);//小数点后面的数字
f2 = str[E + ];
num3.assign(str.begin() + E + , str.end());//指数
for (int i = ; i < num3.length(); ++i)//计算指数
Exp = Exp * + num3[i] - '';
if (f1 == "-")
res += "-";
if (f2 == "-")
{
res += "0.";
res.insert(res.end(), Exp - , '');//中间插入0
}
else if (f2 == "+")
{
if (num2.length() <= Exp)//小数位不足,则直接末尾加0;
num2.insert(num2.end(), Exp - num2.length(), '');
else//小数位多余幂次,则小数点后移
num2.insert(num2.begin() + Exp, , '.');
}
res += num1 + num2;
cout << res << endl;
return ;
}
PAT甲级——A1073 Scientific Notation的更多相关文章
- PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very ...
- PAT甲级——1073 Scientific Notation (20分)
Scientific notation is the way that scientists easily handle very large numbers or very small number ...
- PAT A1073 Scientific Notation (20 分)——字符串转数字
Scientific notation is the way that scientists easily handle very large numbers or very small number ...
- A1073. Scientific Notation
Scientific notation is the way that scientists easily handle very large numbers or very small number ...
- PAT Advanced 1073 Scientific Notation (20 分)
Scientific notation is the way that scientists easily handle very large numbers or very small number ...
- PAT_A1073#Scientific Notation
Source: PAT A1073 Scientific Notation (20 分) Description: Scientific notation is the way that scient ...
- PAT 1073 Scientific Notation[字符串处理][科学记数法]
1073 Scientific Notation(20 分) Scientific notation is the way that scientists easily handle very lar ...
- PAT 1073 Scientific Notation
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very ...
- PAT Basic 1024 科学计数法 (20 分) Advanced 1073 Scientific Notation (20 分)
科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式 [+-][1-9].[0-9]+E[+-][0-9]+,即数字的整数部分只有 1 位,小数部分至少有 1 位,该数字及其指 ...
随机推荐
- JAVA读取PROPERTIES文件方式一
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.i ...
- soj115 御坂网络
题意:平面上有n个A发射点和m个B发射点,可以选择安置相应A/B装置,装置范围是圆,自取半径(要求都相同且<=Rmax).异种要求范围不相交.求装置范围之和(不是并!). 标程: #includ ...
- pipenv的使用
首先,确保pip install pipenv已经安装 1.新建一个文件夹,并在地址栏输入cmd,回车. 2.输入pipenv install,等待虚拟环境搭建完毕. 3.输入pipenv shell ...
- Allegro文档错误之:Iangle 命令
Allegro绘制弧线时,可以使用add rarc命令,或者菜单栏里 Add|Arc w/Radius. 使用该命令时,需要输入3个参数: 1,圆心坐标:如 x –0.3 –0.8 2,半径,以及起始 ...
- thinkphp 范围标签
范围判断标签包括in notin between notbetween四个标签,都用于判断变量是否中某个范围. 大理石平台价格 IN和NOTIN 用法: 假设我们中控制器中给id赋值为1: $id = ...
- 概率dp——处理分母为0的情况hdu3853
很水的题,但要注意的是必须处理分母为0的情况 #include<bits/stdc++.h> using namespace std; ; ; ],e[maxn][maxn]; int r ...
- Android中visibility属性
Android开发中,大部分控件都有visibility这个属性,其属性有3个分别为“visible ”.“invisible”.“gone”.主要用来设置控制控件的显示和隐藏. 1) 可见(visi ...
- c#上传下载ftp(支持断点续传)
using System;using System.Net;using System.IO;using System.Text;using System.Net.Sockets;namespace f ...
- win 7 下安装GIT(亲测有效)
我首先是百度到了这个网站:https://git-scm.com/download/win 当然由于外网访问速度的缓慢 可以直接在百度搜索下载自己对应的版本 这个网站上有下载链接,你可以根据你的系统选 ...
- (转)Python成长之路【第九篇】:Python基础之面向对象
一.三大编程范式 正本清源一:有人说,函数式编程就是用函数编程-->错误1 编程范式即编程的方法论,标识一种编程风格 大家学习了基本的Python语法后,大家就可以写Python代码了,然后每个 ...