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 ...
随机推荐
- Mybatis中 collection 和 association 的区别?
public class A{ private B b1; private List<B> b2;} 在映射b1属性时用association标签,(一对一的关系) 映射b2时用colle ...
- grep精确匹配搜索某个单词的用法 (附: grep高效用法小结))
grep(global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正 ...
- linux下文件加密方法总结
为了安全考虑,通常会对一些重要文件进行加密备份或加密保存,下面对linux下的文件加密方法做一简单总结: 方法一:gzexe加密这种加密方式不是非常保险的方法,但是能够满足一般的加密用途,可以隐蔽脚本 ...
- 对于League of Legends的分析
League of Legends是一款在国内甚至国际上都很受欢迎的一款网络竞技行的游戏.它是由美国Riot Games开发,腾讯游戏运营的英雄对战网游.<英雄联盟>除了即时战略.团队作战 ...
- ☆C++学习心得
C++是我进大学的学的第一种编程语言,在高中的时候有电脑课,有教过部分的VB语言,所以其实对编程也并不是非常的陌生,刚开是上课也觉得感觉不难,都懂,没多少课后,恍了个神..居然听不懂了!老师经常让我们 ...
- 探秘Java中的String、StringBuilder以及StringBuffer(转载)
探秘Java中String.StringBuilder以及StringBuffer 相信String这个类是Java中使用得最频繁的类之一,并且又是各大公司面试喜欢问到的地方,今天就来和大家一起学习一 ...
- Java的JDK下StringBuffer与StringBuilder的区别
下载JDK的源码,咱自己分析下: 用Beyond Compare打开看一下吧 1.他俩的历史问题: StringBuffer:* Copyright (c) 2003, 2008, Oracle an ...
- Windows环境搭建mysql服务器
Windows环境搭建mysql服务器: 1.下载mysql-installer-community-5.7.3.0-m13.2063434697并安装 安装详细步骤>> 2.安装mys ...
- [转帖]VBS 教程
VBS教程 http://www.cnblogs.com/veggiegfei/p/5943260.html 原作者真牛B 网上找了好多 没找到 没想到整理的这么好, 转来学习一下 改天打印出来. V ...
- [日常工作]Oracle新增数据文件的小知识点
1. 表空间是small file tablespace的 然后数据文件长到了32g左右之后无法再次扩充, 应用报错了 为了性能和最快的处理 使用语句 alter tablespace user ad ...