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;

int main()
{
    scanf("%s",s);
    for(int i=0;s[i];i++) if(s[i]==‘E‘) p=i;

    if(s[0]==‘-‘) printf("%c",s[0]);

    int num=0;
    for(int i=p+2;s[i];i++) num=num*10+s[i]-‘0‘;

    if(s[p+1]==‘-‘)
    {
        printf("0.");
        for(int i=0;i<num-1;i++) printf("0");
        for(int i=1;s[i];i++)
        {
            if(s[i]==‘E‘) break;
            if(s[i]==‘.‘) continue;
            else printf("%c",s[i]);
        }
    }

    else
    {
        int d;
        for(int i=1;s[i];i++)
        {
            if(s[i]==‘.‘) d=i;
        }
        if(p-d-1>num)
        {
            if(s[1]!=‘0‘) printf("%c",s[1]);
            for(int i=3;i<3+num;i++) printf("%c",s[i]);
            printf(".");
            for(int i=3+num;s[i];i++)
            {
                if(s[i]==‘E‘) break;
                printf("%c",s[i]);
            }
        }
        else
        {
            for(int i=1;s[i];i++)
            {
                if(s[i]==‘E‘) break;
                if(s[i]==‘.‘) continue;
                if(i==1&&s[i]==‘0‘) continue;
                printf("%c",s[i]);
            }
            for(int i=0;i<num-(p-d-1);i++) printf("0");
        }
    }
    return 0;
}
时间: 2024-10-07 02:45:14

PAT (Advanced Level) 1073. Scientific Notation (20)的相关文章

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(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分)

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

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)-字符串处理

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

PAT (Advanced Level) 1100. Mars Numbers (20)

简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; char a[20][6]={ "tret","jan"

PAT (Advanced Level) 1096. Consecutive Factors (20)

如果是素数直接输出1与素数,否则枚举长度和起始数即可. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; long long n; bool prime(

PAT (Advanced Level) 1081. Rational Sum (20)

简单模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<algorithm> using namespace std; struct FenShu { long l

PAT (Advanced Level) 1084. Broken Keyboard (20)

简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; const int maxn=100000; char s[maxn],t[maxn],u[m