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的更多相关文章

  1. PAT A1073 Scientific Notation (20 分)——字符串转数字

    Scientific notation is the way that scientists easily handle very large numbers or very small number ...

  2. PAT甲级——A1073 Scientific Notation

    Scientific notation is the way that scientists easily handle very large numbers or very small number ...

  3. PAT_A1073#Scientific Notation

    Source: PAT A1073 Scientific Notation (20 分) Description: Scientific notation is the way that scient ...

  4. 1073 Scientific Notation (20 分)

    1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very la ...

  5. Excel scientific notation issue

        This is a known issue, you can find more in internet. Excel will treat text(can display with num ...

  6. 1073. Scientific Notation (20)

    题目如下: Scientific notation is the way that scientists easily handle very large numbers or very small ...

  7. PAT 1073 Scientific Notation

    1073 Scientific Notation (20 分)   Scientific notation is the way that scientists easily handle very ...

  8. PAT 1073 Scientific Notation[字符串处理][科学记数法]

    1073 Scientific Notation(20 分) Scientific notation is the way that scientists easily handle very lar ...

  9. PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)

    1073 Scientific Notation (20 分)   Scientific notation is the way that scientists easily handle very ...

随机推荐

  1. Ionic 2 中生命周期的命名改变及说明

    原文发表于我的技术博客 本文简要整理了在 Ionic 2 的版本中生命周期命名的改变,以及各个事件的解释. 原文发表于我的技术博客 在之前的课程中讲解了 Ionic 生命周期的命名以及使用,不过在 I ...

  2. grep精确匹配搜索某个单词的用法 (附: grep高效用法小结))

    grep(global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正 ...

  3. Gitblit版本服务器环境部署记录

    Gitblit介绍Gitblit 是一个纯 Java 库用来管理.查看和处理 Git 资料库.相当于 Git 的 Java 管理工具,支持linux系统.Git是分布式版本控制系统,它强调速度.数据一 ...

  4. [Beta]M2事后分析

    计划 你原计划的工作是否最后都做完了? 如果有没做完的,为什么? 答:没有,全部的功能没有实现.其中,界面还差两个,逻辑还差闹钟逻辑和群组逻辑,可以说这些东西是我们的核心功能之一,缺失了他们对我们整个 ...

  5. poj 1723 SOLDIERS 带权中位数

    题目 http://poj.org/problem?id=1723 题解 带权中位数类型的题目~ 可以先考虑降维,最后集合的y坐标,明显是y坐标的中位数的位置,容易求出y方向的贡献res_y.比较麻烦 ...

  6. a simple example for spring AOP

    /** * Created by Administrator on 2015/11/25. * a interface */public interface ArithmeticCalculator{ ...

  7. 关于RESTful 的概念

    1.REST 是面向资源的,这个概念非常重要,而资源是通过 URI 进行暴露.URI 的设计只要负责把资源通过合理方式暴露出来就可以了.对资源的操作与它无关,操作是通过 HTTP动词来体现,所以RES ...

  8. [转帖]看完这篇文章你还敢说你懂JVM吗?

    看完这篇文章你还敢说你懂JVM吗? 在一些物理内存为8g的服务器上,主要运行一个Java服务,系统内存分配如下:Java服务的JVM堆大小设置为6g,一个监控进程占用大约 600m,Linux自身使用 ...

  9. [转帖] kubeadm搭建kubernetes集群

    http://www.bladewan.com/2018/01/02/kubernetes_install/ 学习中 kubernetes V1.9安装(附离线安装包和离线镜像)  2018-01-0 ...

  10. 转《trackingjs+websocket+百度人脸识别API,实现人脸签到》流程

    先用websocket与后台建立通讯:用trackingjs在页面调用电脑摄像头,监听人脸,发现有人脸进入屏幕了,就把图片转成base64字符串,通过websocket发送到后端:后端拿到图片,调用百 ...