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 file 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<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int main(){
char c_sign, p_sign, num[];
int pos, tag = , power = ;
scanf("%c", &c_sign);
scanf("%s", num);
for(int i = ; num[i] != '\0'; i++){
if(num[i] == 'E'){
pos = i;
num[i] = '\0';
p_sign = num[++i];
tag = ;
continue;
}
if(tag == )
power = power * + num[i] - '';
}
if(p_sign == '+'){
int j;
for(j = ; j < pos - && j <= power; j++)
swap(num[j], num[j + ]);
if(j <= power){
while(j <= power){
num[j++] = '';
}
num[j] = '\0';
}
if(num[strlen(num) - ] == '.')
num[strlen(num) - ] = '\0';
if(c_sign == '-')
printf("%c", c_sign);
for(j = ; num[j] != '\0'; j++)
if(num[j] == '' && num[j + ] != '' || num[j] != '')
break;
for( ; num[j] != '\0'; j++)
printf("%c", num[j]);
}
if(p_sign == '-'){
int j;
if(c_sign == '-')
printf("%c", c_sign);
if(power != ){
swap(num[], num[]);
printf("0.");
for(j = ; j < power - ; j++)
printf("");
for(j = ; num[j] != '\0'; j++)
printf("%c", num[j]);
}else{
printf("%s", num);
}
}
cin >> num;
return ;
}
总结:
1、首先由题意可知,底数有可能非常长,最终得到的数字长度可达9999B,为保证能全部输出,只能采用字符串处理的方式,而不能直接用long型计算得出。
2、基本思路:将整个数字分为四部分,底数的符号,指数的符号,底数,指数。其中指数范围较小,可以用int型存储,底数用字符串存储。再分为小数点左移与右移来分类处理。其中向右移动时,如果小数点移动后位于最后一位,则不输出小数点。
A1073. Scientific Notation的更多相关文章
- PAT A1073 Scientific Notation (20 分)——字符串转数字
Scientific notation is the way that scientists easily handle very large numbers or very small number ...
- PAT甲级——A1073 Scientific Notation
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 ...
- 1073 Scientific Notation (20 分)
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very la ...
- Excel scientific notation issue
This is a known issue, you can find more in internet. Excel will treat text(can display with num ...
- 1073. Scientific Notation (20)
题目如下: Scientific notation is the way that scientists easily handle very large numbers or very small ...
- PAT 1073 Scientific Notation
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very ...
- PAT 1073 Scientific Notation[字符串处理][科学记数法]
1073 Scientific Notation(20 分) Scientific notation is the way that scientists easily handle very lar ...
- PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very ...
随机推荐
- macaca使用中问题解决方法整理
报告老板:很多同学在搭建macaca的环境时候,出现了各种问题,尤其是使用windows的同学,更是复杂且费劲的要命,我这里针对一些遇到的坑,按照从头的搭建开始说起,如下 基本的搭建条件要满足基础环境 ...
- linux journalctl 命令
目录 Help 输出所有的日志记录 匹配(match) 把日志保存到文件中 限定日志所能占用的最高容量 查看某次启动后的日志 查看指定时间段的日志 同时应用 match 和时间过滤条件 按 unit ...
- monkey测试基础
一.环境配置 Java JDK和android SDK 二.基本命令 *安卓手机链接电脑,打开手机的开发者模式,允许usb调试 adb:检查adb是否安装成功 adb devices:查看连接的设备 ...
- 老牌阅读器nook2刷机整理
kindle肯定是现在大多数人了解电纸书这个产品的开端,也给我留下了一段美好的回忆,不折腾,不死机,官方书城让人省心不少,不过作为半个折腾爱好者,kindle显然不符合我的理念,遂慢慢入了安卓电纸书的 ...
- linux书籍
<鸟哥私房菜-基础版> <实战LINUX_SHELL编程与服务器管理> <LINUX命令行与SHELL脚本编程大全第2版].布卢姆.扫描版> <Linux初学 ...
- pom.xml mevan 的 配置文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- [系统软件]Ubuntu 18.04中的Shutter禁用了“编辑”选项解决
本文引用自linux公社, 原文请点击 : https://www.linuxidc.com/Linux/2018-04/151911.htm 在Ubuntu 18.04中安装了我最喜欢的截图工具 ...
- activiti engine.schema.update DB_SCHEMA_UPDATE_FALSE
engine.properties # engine propertiesengine.schema.update=trueengine.activate.jobexecutor=falseengin ...
- VUE的语法笔记
v-model = 'content' {{contents}} //vue 双向视图的绑定 v-text 只能返回一个文本内容 v-html 不仅可以返回文本内容还可以返回html标签 v-for ...
- 简单的数据库备份语句--Oracle+SQLSERVER
1. 工作中经常需要备份数据库表, 有时候经常需要baidu或者是询问,简单些一下.. 如果备份表不存在时: Oracle的语法 create table zhaobsh as select * fr ...