• csp模拟题-201903


    1.小中大(100分)

    #include<iostream> 
    #include<cstdio>
    #define maxn 100010
    using namespace std;
    int a[maxn],n;
    int main(){
        scanf("%d",&n);
        for(int i=1;i<=n;i++)scanf("%d",&a[i]);
        int x,z;
        double y;
        x=a[1];z=a[n];
        if(x<z)swap(x,z);
        printf("%d ",x);
        if(n%2==0){
            y=(double)(a[n/2]+a[n/2+1])/2.0;
        }
        else {
            y=a[n/2+1];
        }
        if(y==(int)y)printf("%.0f ",y);
        else printf("%.1f ",y);
        printf("%d
    ",z);
        return 0;
        
    }

    2.二十四点(100分)

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int n,st[10],top;
    char s[10];
    int main(){
        freopen("Cola.txt","r",stdin);
        scanf("%d",&n);
        while(n--){
            top=0;
            scanf("%s",s+1);
            int pre=1; 
            for(int i=1;i<=7;i++){
                if(s[i]<='9'&&s[i]>='1'){
                    int a=s[i]-'0';
                    st[++top]=pre*a;
                }
                else{
                    if(s[i]=='+')pre=1;
                    else if(s[i]=='-')pre=-1;
                    else if(s[i]=='x'){
                        int b=s[i+1]-'0';
                        int a=st[top];
                        st[top]=a*b;
                        i++;
                    }
                    else{
                        int b=s[i+1]-'0';
                        int a=st[top];
                        st[top]=a/b;
                        i++;
                    }
                }
            }
            int ans=0;
            for(int i=1;i<=top;i++)ans+=st[i];
    //        printf("%d
    ",ans); 
            if(ans==24){puts("Yes");}
            else {puts("No");}
        }
        return 0;
    }
  • 相关阅读:
    ABAP中COLLECT的用法
    中文字符串提交乱码的解决方法
    我的Ubuntu系统
    SAP消息呈现
    ASP.NET博客站点全静态化的困扰
    JS利用函数修改全局变量
    让电脑速度增快几倍的法宝
    我的Ubuntu门派
    给老乡买本本的经历
    多事之秋
  • 原文地址:https://www.cnblogs.com/thmyl/p/12041460.html
Copyright © 2020-2023  润新知