PAT 1073 Scientific Notation
来源:互联网 发布:天狼星期货软件管网 编辑:程序博客网 时间:2024/06/11 20:06
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-03Sample Output 1:
0.00123400Sample Input 2:
-1.2E+10Sample Output 2:
-12000000000
解题思路: 简单的字符串处理题,输入格式固定,只需根据阶数与小数长度的关系判断是否补零。
#include<stdio.h>
#include<string.h>int main()
{
int i,j,cnt=0,sum=0,len;
char num[100000],temp[100000],sign_n,sign_e,neg='-';
scanf("%s",num);len=strlen(num);
sign_n=num[0];
for(i=1,j=0;i<len;i++)
{
if(num[i]=='E')
break;
if(i!=2)
temp[j++]=num[i];
if(i>2)cnt++;
}
if(sign_n==neg)
putchar(neg);
sign_e=num[++i];
while(num[++i]==48&&i<len);
for(;i<len;i++)
sum=sum*10+(num[i]-48);
if(sign_e==neg)
{
putchar(48);
putchar('.');
while(--sum)putchar(48);
printf("%s",temp);
}
else
{
if(cnt>sum)
{
for(i=0;i<=sum;i++)
putchar(temp[i]);
putchar('.');
for(;i<=cnt;i++)
putchar(temp[i]);
}
else
{
//printf("sum=%d cnt=%d\n",sum,cnt);
printf("%s",temp);
for(i=1;i<=sum-cnt;i++)
putchar(48);
}
}
putchar('\n');
return 0;
}
- PAT 1073 Scientific Notation
- Pat 1073 PAT 1073. Scientific Notation (20)
- Pat(Advanced Level)Practice--1073(Scientific Notation)
- PAT 1073. Scientific Notation
- PAT 1073. Scientific Notation
- 【PAT】1073. Scientific Notation
- pat 1073. Scientific Notation
- PAT 1073. Scientific Notation (20)
- PAT 1073. Scientific Notation (20)
- PAT 1073. Scientific Notation (20)
- PAT 1073. Scientific Notation (20)
- PAT 1073. Scientific Notation(20)
- PAT 1073. Scientific Notation (20)
- PAT 1073. Scientific Notation (20)
- 【PAT】1073. Scientific Notation (20)
- 【PAT】A1073. Scientific Notation (20)
- PAT A1073. Scientific Notation (20)
- PAT (Advanced Level) Practise 1073 Scientific Notation (20)
- Eclipse中更改默认java代码格式
- Codeforces Round #294 (Div. 2) (ABCDE题解)
- 如何思考问题与表达问题
- MySQL编码解析
- ZeroMQ
- PAT 1073 Scientific Notation
- 压缩bitmap时返回null的问题
- 电焊与气割
- 黑马程序员——正则表达式(2)自制模糊查询
- 构造函数
- 新学期幼儿园致家长的一封信
- pomelo在android编译时出现的错误解决方案
- 初始化列表
- (转)Android利用canvas画各种图形(点、直线、弧、圆、椭圆、文字、矩形、多边形、曲线、圆角矩形)