• 华东师范大学2013年编程实践课程非师范班第1次上机考试 前4题


    2976

    #include <stdio.h>
    #define MAX 3
     
    int main()
    {
        int pn; //problem count
        int a[MAX][MAX];
        int b[MAX][MAX];
     
        scanf("%d",&pn);
        int c=0; //case
     
        while (c<pn)
        {
            int n;
            int i,j;
            for (i=0;i<MAX;i++)
            {
                for (j=0;j<MAX;j++)
                {
                    scanf("%d",&n);
                    a[i][j]=n%2;
                }
            }
     
            b[0][0]=1-(a[0][0]+a[0][1]+a[1][0])%2;
            b[0][1]=1-(a[0][0]+a[0][1]+a[0][2]+a[1][1])%2;
            b[0][2]=1-(a[0][1]+a[0][2]+a[1][2])%2;
     
            b[1][0]=1-(a[0][0]+a[1][0]+a[2][0]+a[1][1])%2;
            b[1][1]=1-(a[1][0]+a[0][1]+a[1][2]+a[2][1]+a[1][1])%2;
            b[1][2]=1-(a[0][2]+a[1][2]+a[2][2]+a[1][1])%2;
     
            b[2][0]=1-(a[1][0]+a[2][0]+a[2][1])%2;
            b[2][1]=1-(a[2][0]+a[2][1]+a[2][2]+a[1][1])%2;
            b[2][2]=1-(a[2][1]+a[1][2]+a[2][2])%2;
     
     
            printf("case #%d:\n",c);
            c++;
            for (i=0;i<MAX;i++)
            {
                for (j=0;j<MAX-1;j++)
                    printf("%d ",b[i][j]);
                printf("%d\n",b[i][j]);
            }
        }
     
        return 0;
    }

    2977

    #include <iostream>
    #include <string>
    #include <algorithm>  
    #define MAX 3
    
    using namespace std;
    
    struct stu_score
    {
        string id;
        int score;
    };
    
    int Compare(const void* a, const void* b)
    {
        stu_score stu1=*(stu_score*)a;
        stu_score stu2=*(stu_score*)b;
    
        if(stu1.score>stu2.score) return -1;
        if(stu1.score==stu2.score) 
        {
            if(stu1.id<stu2.id) return -1;
            if(stu1.id>=stu2.id) return 1;
        }
        if(stu1.score<stu2.score) return 1;
    }
    
    bool Compare1(stu_score stu1,stu_score stu2)
    {
        if(stu1.score==stu2.score) return stu1.id>stu2.id;
        else return stu1.score>stu2.score;
    }
    
    int main()
    {
    
        int T; //problem count
        scanf("%d",&T);
        int c=0; //case
    
        while (c<T)
        {
            int N,M,G,passNum=0;
            int a[11];
            int i,j;
            stu_score s[500];
    
            cin>>N>>M>>G;
            for (i=1;i<=M;i++) cin>>a[i];
    
            for (i=0;i<N;i++) 
            {
                cin>>s[i].id;
                int S,sum=0;
                cin>>S;
                for (j=0;j<S;j++) 
                {
                    int t;
                    cin>>t;
                    sum+=a[t];
                }
                s[i].score=sum;
                if (sum>=G) passNum++;
            }
    
    
            //sort(s,s+N,Compare1);
    
            cout<<"case #"<<c<<":\n";
            cout<<passNum<<endl;
            qsort(s,N,sizeof(stu_score), Compare);
            for (i=0;i<N;i++)
            {
                if (s[i].score>=G)
                    cout<<s[i].id<<" "<<s[i].score<<endl;
            }
            c++;
        }
    
        return 0;
    }

    2978

    #include <stdio.h>
    #include <iostream>
    #define MAX 3
    
    using namespace std;
    
    int main()
    {
        int T,ca=0;
    
        cin>>T;
        while (ca<T)
        {
            __int64 A;
            cin>>A;
            //int i;
            while(true)
            {
                int a=A%1000/100;
                int b=A%100/10;
                int c=A%10;
                if (c==0) break;
                int d=(a+b)*c;
                A=A*10+d%10;
            }
    
            int sum=0;
            while(A!=0)
            {
                sum+=A%10;
                A/=10;
            }
            cout<<"case #"<<ca<<":\n";
            cout<<sum<<"\n";
            ca++;
        }
    
        return 0;
    }

    2979

    #include <stdio.h>
    #define MAX 80
    
    void InitializeZigZagArray(int a[][MAX])
    {
    
        a[0][0]=1;
        a[0][1]=2;
        a[1][1]=3;
        a[1][0]=4;
    
        int x,y=0; //Initial coordinate
        int row=2;  //Starting row of iteration
        int counter=5;
    
        while(true)
        {
            x=row;
            //go right
            while(true)
            {
                a[x][y]=counter++;
                if (y==row) break;
                y++;
            }
            
    
            //go up
            x--;
            while(true)
            {
                a[x][y]=counter++;
                if (x==0) break;
                x--;
            }
    
            //go right
            y++;
    
            //go down
            while(true)
            {
                a[x][y]=counter++;
                if (x==row+1) break;
                x++;
            }
            y--;
            //go left
            while(true)
            {
                a[x][y]=counter++;
                if (y==0) break;
                y--;
            }
    
            if (x==MAX-1) return;
            row+=2;        
        }
    }
    
    
    int main()
    {
        int pn; //problem count
        int a[MAX][MAX];
        InitializeZigZagArray(a);
    
        scanf("%d",&pn);
        int c=0; //case
    
        while (c<pn)
        {
            int n;
            scanf("%d",&n);
            //n=MAX;
            printf("case #%d:\n",c);
            c++;
    
            int i,j;
            for (i=0;i<n;i++)
            {
                for (j=0;j<n-1;j++)
                    printf("%d ",a[i][j]);
                printf("%d\n",a[i][j]);
            }
        }
    
        return 0;
    }
  • 相关阅读:
    前端如何进阶架构师
    NPOI使用记录
    ArcGis 中空间数据的插入与更新
    (转载).net 缓存处理
    ASP.NET(c#)实现重定向的三种方法的总结
    数据库关联表之间的更新语句
    C#net多线程多文件压缩下载
    关于写文件流的情况
    C# Class获取项目的绝对路径
    C# .net中DatailsView的JS简易版
  • 原文地址:https://www.cnblogs.com/zijinzhengfeng/p/2975948.html
Copyright © 2020-2023  润新知