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 ...
随机推荐
- nginx域名访问的白名单配置梳理
在日常运维工作中,会碰到这样的需求:设置网站访问只对某些ip开放,其他ip的客户端都不能访问.可以通过下面四种方法来达到这种效果:1)针对nginx域名配置所启用的端口(比如80端口)在iptable ...
- python基础学习笔记(十三)
re模块包含对 正则表达式.本章会对re模块主要特征和正则表达式进行介绍. 什么是正则表达式 正则表达式是可以匹配文本片段的模式.最简单的正则表达式就是普通字符串,可以匹配其自身.换包话说,正则表达式 ...
- 剑指offer:二叉树中和为某一值的路径
本来这只是一个普通的算法题,但是当初自己OJ上提交时,总是提交失败,而我自己认定程序逻辑没有任何问题.然后开始就在本机上调试,结果发现这是由于Python的对象机制而引发的.所以先把问题算法题贴出来, ...
- C_运算符_逻辑表达式
// 除法取余运算符的例子 //2018年9月19日22:44:21 # include<stdio.h> int main(void) { printf(%, %-, -%, -%-, ...
- 算法模板学习专栏之总览(会慢慢陆续更新ing)
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/7495310.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- box-flex 弹性合布局+WebApp布局自适应
问:随着屏幕改变,中间自适应 两边固定宽度? 参考: nec 布局 四种方法--博客园 问:左侧导航栏隐藏后,右侧内容宽度自动(响应式)变大? <!DOCTYPE html> <ht ...
- Pair_Work Project
结对项目小记 ——by 12061227 康 12061179 宇帆 结对编程就是一种敏捷软件开发的方法,两个人在一个计算机上共同工作.一个人输入,而另一个人检查他输入的每一行代码.输入代 ...
- spring引入HikariCP连接池
1.导入jar包 2.applicationContext.xml中配置 <bean id="dataSource" class="com.zaxxer.hikar ...
- Unigine mesh顶点坐标转换精度问题
本问题虽然与Unigine引擎相关,但对其他精度问题也有参考价值. 问题: 将精细模型顶点从自身参考系的相对坐标(类似4378.95020,4561.00000,31.3887463) 转到椭球面世界 ...
- QT下opencv的编译和使用
需要的文件 qt-opensource-windows-x86-mingw491_opengl-5.4.0.exe cmake-3.12.0-rc1-win64-x64.msi opencv-2.4. ...