1073 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 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
/*
    Name:
    Copyright:
    Author:  流照君
    Date: 2019/8/22 9:58:53
    Description:
*/
#include <iostream>
#include<string>
#include <algorithm>
#include <vector>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
string s;
int main(int argc, char** argv)
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ll flag=0,flag1,flag2,sum=0,e,flag3,k=0;
    cin>>s;
    if(s[0]==‘-‘)
    flag=0;
    else
    flag=1;
    for(ll i=1;i<s.length();i++)
    {
    	if(s[i]==‘E‘)
    	{
    		e=i;
    		if(s[i+1]==‘-‘)
    		flag1=0;
    		else
    		flag1=1;
    		flag3=i+1;
		}
		if(i>flag3)
		{
			sum=sum*10+s[i]-‘0‘;
		}
	}
	//cout<<sum<<endl;
	if(sum==0)//这个不写竟然没关系!
	{
		for(int i=0;i<e;i++)
		cout<<s[i];
		cout<<endl;
	}
	else
	{
	if(flag1==0)
	{
		if(flag==0)
		cout<<‘-‘;
		cout<<"0.";
		for(int i=1;i<sum;i++)
		cout<<‘0‘;
		for(int i=1;i<e;i++)
		{
			if(i==2)
			continue;
			cout<<s[i];
		}
		cout<<endl;
	}
	else
	{
		if(flag==0)
		cout<<‘-‘;
		for(ll i=1;i<e;i++)
		{
			if(i==2)
			{
				k=0;
				continue;
			}
			cout<<s[i];
			k++;
			if(k==sum&&i!=(e-1))
			cout<<‘.‘;
		}
		for(ll i=1;i<=sum-(e-2-1);i++)
		cout<<‘0‘;
		cout<<endl;
	}
}
    return 0;
}

k如果是局部变量得初始化为0,否则就设为全局变量自动初始化为0,

不初始化k会出现各种奇怪的错误

这或许就是玄学吧

原文地址:https://www.cnblogs.com/liuzhaojun/p/11393608.html

时间: 2024-10-25 19:40:01

1073 Scientific Notation的相关文章

PAT 1073. Scientific Notation (20)

1073. Scientific Notation (20) 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

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

1073 Scientific Notation(20 分) 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 exa

1073. Scientific Notation (20)

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

PAT(A) 1073. Scientific Notation (20)

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

[PAT] 1073 Scientific Notation (20 分)Java

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 lea

PAT甲级——1073 Scientific Notation (20分)

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 lea

pat(A) 1073. Scientific Notation(水题)

1.链接:点击打开链接 2.代码: #include<cstdio> #include<cstring> #include<iostream> using namespace std; char s[100000]; char ss[100000]; int f[10]; int main() { f[0]=1; for(int i=1; i<9; i++) { f[i]=f[i-1]*10; } while(scanf("%s",s)==1)

PAT (Advanced Level) 1073. Scientific Notation (20)

简单模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<algorithm> using namespace std; char s[100000]; int p;

PAT甲题题解-1073. Scientific Notation (20)-字符串处理

题意:给出科学计数法的格式的数字A,要求输出普通数字表示法,所有有效位都被保留,包括末尾的0. 分两种情况,一种E+,一种E-.具体情况具体分析╮(╯_╰)╭ #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <cmath> #define POSITIVE 1 #define NEGATIVE 2 using names