Do title records --day51

PAT B1024

Ah ah ah ah this title card day has finally passed ah! ! !

A few notes, first of all,

In the latter case positive index number, may be considered to be in front of the multiple 0, for example + 0.01E + 03, to remove the front 0

There is a case where the number of index finished up precisely, the end of which time the decimal point should be removed, such as + 1.23E + 02, it is not determined 123.

And in the case of a negative index should also be considered up 0

Note that at the time of submission remove write your own printf

#include<stdio.h>
#include<string.h>
int main()
{
    char str[100000];
    while(scanf("%s",str)!=EOF)
    {
        int e,symbol1,symbol2;
        int len=strlen(str);
        if(str[0]=='+')
            symbol1=1;
        else
            symbol1=2;
        for(int i=2;i<=len-1;i++)
        {
            if(str[i]=='E')
            {
                e=i;
                break;
            }
        }
        if(str[e+1]=='+')
            symbol2=1;
        else
            symbol2=2;
        int up=e+2;
        while(str[up]=='0')
            up++;
        int count=1;
        int ans=0;
        int temp[10005];
        int tempnum=0;
        while(up<=len-1)
        {
            temp[tempnum++]=str[up]-'0';
            up++;
        }
        for(int i=tempnum-1;i>=0;i--)
        {
            ans+=count*temp[i];
            count=count*10;
        }
        //printf("symbol1:%d,e:%d,symbol2:%d,ans:%d\n",symbol1,e,symbol2,ans);
        if(symbol2==1)
        {
            int zero=1;
            if((ans+3)<e)
            {
                for(int i=2;i<=1+ans;i++)
                    str[i]=str[i+1];
                /*for(int i=e-1;i>ans+2;i--)
                    str[i+1]=str[i];*/
                str[ans+2]='.';
                if(str[0]=='-')
                    printf("-");
                while(str[zero]=='0')
                    zero++;
                if(str[zero]=='.')
                    zero--;
                for(int i=zero;i<e;i++)
                printf("%c",str[i]);
                printf("\n");
            }
            else if(ans+3==e)
            {
                for(int i=2;i<=1+ans;i++)
                    str[i]=str[i+1];
                //str[ans+2]='.';
                if(str[0]=='-')
                    printf("-");
                while(str[zero]=='0')
                    zero++;
                if(str[zero]=='.')
                    zero--;
                //printf("zero:%d\n",zero);
                for(int i=zero;i<e-1;i++)
                printf("%c",str[i]);
                printf("\n");
            }
            else
            {
                for(int i=2;i<=e-2;i++)
                    str[i]=str[i+1];
                for(int i=e-1;i<=ans+1;i++)
                    str[i]='0';
                if(str[0]=='-')
                    printf("-");
                while(str[zero]=='0')
                    zero++;
                if(str[zero]=='.')
                    zero--;
                for(int i=zero;i<=ans+1;i++)
                    printf("%c",str[i]);
                printf("\n");
            }
        }
        else
        {
            for(int i=e-1+ans;i>=ans+3;i--)
                str[i]=str[i-ans];
            str[ans+2]=str[1];
            str[1]='0';
            str[2]='.';
            for(int i=1;i<=ans-1;i++)
                str[2+i]='0';
            if(str[0]=='-')
                printf("-");
            for(int i=1;i<=e-1+ans;i++)
                printf("%c",str[i]);
            printf("\n");
        }
    }
    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/tingxilin/p/11469539.html