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型存储,底数用字符串存储。再分为小数点左移与右移来分类处理。其中向右移动时,如果小数点移动后位于最后一位,则不输出小数点。

最新文章

  1. 通过Matrix进行二维图形仿射变换
  2. 生产/消费 发送和接收消息---基于kombu和redis交互
  3. python操作
  4. PHP 如何显示大数字,防止显示为 科学计数法 形式
  5. [C++] 如何查看DLL有哪些函数
  6. 鼠标滚动插件smoovejs和wowjs
  7. strcat函数造成的段错误(Segmentation fault)
  8. Linux 配置本地yum源
  9. 理解Javascript 的闭包(closure)
  10. BZOJ 3570 动物园
  11. AndroidStudio SVN检出
  12. 把所有的QT的类都过一遍脑子
  13. STM32建立project库函数方法
  14. moodle笔记之-权限api
  15. Python 变量作用域,闭包和装饰器
  16. [随笔][胡思乱想][唠叨][web server]
  17. Flask-Session 简单使用
  18. 微信公共号:CTO技术总监
  19. ACM:油田(Oil Deposits,UVa 572)
  20. vue Watcher分类 computed watch

热门文章

  1. Docker容器学习梳理 - 容器登陆方法梳理(attach、exec、nsenter)
  2. og标签对SEO的作用及用法
  3. 【个人阅读作业】软件工程M1/M2总结
  4. 读书笔记(chapter3)
  5. 实现基于SSH的门票管理系统开发的质量属性
  6. [福大软工] Z班——Beta现场答辩反馈
  7. CAS的应用场景
  8. Linux下运行Shell脚本或者可执行文件Executable方法
  9. Spring源码阅读学习一
  10. java中的随机数Random