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)
    {
        int len=strlen(s);
        if(s[0]=='-')
            printf("-");
        int pos=1;
        int poss=0;
        while(s[pos]!='E')
        {
            if(s[pos]!='.')
            {
                ss[poss]=s[pos];
                poss++;
                pos++;
            }
            else
            {
                pos++;
            }
        }
        pos++;
        int num=0;
        int cnt=0;
        for(int i=len-1; i>pos; i--)
        {
            num+=((s[i]-'0')*f[cnt]);
            cnt++;
        }
        if(s[pos]=='+')
        {
            int i;
            for(i=0; i<=num; i++)
            {
                if(i<poss)
                    printf("%c",ss[i]);
                else
                    printf("0");
            }
            if(num<poss-1)
                printf(".");
            for(i=num+1; i<poss; i++)
            {
                printf("%c",ss[i]);
            }
            printf("\n");
        }
        else
        {
            for(int i=0; i<=num; i++)
            {
                if(i==1)
                    printf(".");
                else
                    printf("0");
            }
            ss[poss]='\0';
            printf("%s",ss);
            printf("\n");
        }
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-16 16:48:40

pat(A) 1073. Scientific Notation(水题)的相关文章

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

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

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

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

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 lea

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) 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;