zoukankan      html  css  js  c++  java
  • 做题记录--day51

    PAT B1024

    啊啊啊啊啊啊啊啊这个题卡了一天终于过了啊!!!

    几个注意事项,首先,

    在后面指数为正数的情况下,需要考虑到前面可能是多0的,比如+0.01E+03,前面0要去掉

    还有就是在指数补完数量正好的情况下,这时候要把末尾小数点去掉,比如+1.23E+02,不判定的话就是123.

    而在指数为负的情况下还要考虑补0

    注意在提交的时候去掉自己写的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
    ",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("
    ");
                }
                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
    ",zero);
                    for(int i=zero;i<e-1;i++)
                    printf("%c",str[i]);
                    printf("
    ");
                }
                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("
    ");
                }
            }
            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("
    ");
            }
        }
        return 0;
    }
    View Code

     PAT B1048

    题没什么难度但是读题就比较坑。。。

    另外注意一下。。JQK不是按照字母顺序的,不能直接'J'-10+temp

    这个注意,无论是A大还是B大,都要处理全部的位数,刚开始以为只有B大考虑。。

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    int main()
    {
        char a[1005];
        char b[1005];
        scanf("%s %s",a,b);
        for(int j=1;j<=min(strlen(a),strlen(b));j++)
        {
            if(j%2==1)
            {
                int temp=((b[strlen(b)-j]-'0')+a[strlen(a)-j]-'0')%13;
                //printf("%d
    ",temp);
                if(temp==10)
                    b[strlen(b)-j]='J';
                else if(temp==11)
                    b[strlen(b)-j]='Q';
                else if(temp==12)
                    b[strlen(b)-j]='K';
                else
                    b[strlen(b)-j]=temp+'0';
            }
            else
            {
                int temp=b[strlen(b)-j]-a[strlen(a)-j];
                if(temp<0)
                {
                    temp=temp+10;
                }
                b[strlen(b)-j]=temp+'0';
            }
        }
        if(strlen(b)>strlen(a))
        {
            for(int j=strlen(a)+1;j<=strlen(b);j++)
            {
                if(j%2==1)
                {
                int temp=((b[strlen(b)-j]-'0'))%13;
                //printf("pos1:%d
    ",temp);
                if(temp==10)
                    b[strlen(b)-j]='J';
                else if(temp==11)
                    b[strlen(b)-j]='Q';
                else if(temp==12)
                    b[strlen(b)-j]='K';
                else
                    b[strlen(b)-j]=temp+'0';
                }
                else
                {
                    int temp=b[strlen(b)-j]-'0';
                    //printf("pos2:%d
    ",temp);
                    if(temp<0)
                    {
                        temp=temp+10;
                    }
                    b[strlen(b)-j]=temp+'0';
                }
            }
            printf("%s",b);
        }
        else if(strlen(a)>strlen(b))
        {
            for(int j=strlen(b)+1;j<=strlen(a);j++)
            {
                if(j%2==1)
                {
                int temp=((a[strlen(a)-j]-'0'))%13;
                //printf("pos1:%d
    ",temp);
                if(temp==10)
                    a[strlen(a)-j]='J';
                else if(temp==11)
                    a[strlen(a)-j]='Q';
                else if(temp==12)
                    a[strlen(a)-j]='K';
                else
                    a[strlen(a)-j]=temp+'0';
                }
                else
                {
                    int temp='0'-a[strlen(a)-j];
                    //printf("pos2:%d
    ",temp);
                    if(temp<0)
                    {
                        temp=temp+10;
                    }
                    a[strlen(a)-j]=temp+'0';
                }
            }
            for(int i=0;i<=strlen(a)-strlen(b)-1;i++)
                printf("%c",a[i]);
            printf("%s",b);
        }
        else
            printf("%s",b);
        //printf("%s %s
    ",a,b);
        return 0;
    }
    View Code
    时间才能证明一切,选好了就尽力去做吧!
  • 相关阅读:
    MySQL知识树 集合操作
    MySQL知识树 查询原理
    MySQL知识树 查询分类
    MySQL知识树 字符类型
    MySQL知识树 日期时间类型
    MySQL知识树 数值类型 位类型
    MySQL知识树 数值类型 浮点数和定点数
    mysql-7 数据检索(5)
    mysql-6 数据检索(4)
    python-1 python基础知识
  • 原文地址:https://www.cnblogs.com/tingxilin/p/11469539.html
Copyright © 2011-2022 走看看