美文网首页C语言学习C语言杭电oj
第12周编程题在线测试

第12周编程题在线测试

作者: 小小Henry | 来源:发表于2019-12-17 21:36 被阅读0次

    1计算时间差V2.0

    # include<stdio.h>
    # include<math.h>
    
    typedef struct clock
    {
    
        int hour;
    
        int minute;
    
        int second;
    
    }CLOCK;
    
    
    void CalculateTime(CLOCK* one, CLOCK* two, CLOCK *three);
    
    
    int main()
    {
        CLOCK one, two, three;
        printf("Input time one:(hour,minute):");
        scanf("%d,%d", &(one.hour), &(one.minute));
        printf("Input time two: (hour,minute):");
        scanf("%d,%d", &(two.hour), &(two.minute));
        CalculateTime(&one, &two, &three);
        printf("%dhour,%dminute\n", three.hour, three.minute);
        return 0;
    }
    
    void CalculateTime(CLOCK* one, CLOCK* two, CLOCK *three)
    {
        int temp;
        temp = fabs((one->hour - two->hour) * 60 + one->minute - two->minute);
        three->hour = temp / 60;
        three->minute = temp % 60;
    }
    

    2奖学金发放

    # include<stdio.h>
    # include<math.h>
    
    typedef struct winners
    
    {
        char name[20];
        int finalScore;
        int classScore;
        char work;
        char west;
        int paper;
        int scholarship;
    } WIN;
    
    void Input(WIN* stu, int n);
    int FindMax(WIN* stu, int n);
    
    int main()
    {
        WIN stu[40];
        int n;
        int m;
        printf("Input n:");
        scanf("%d", &n);
        Input(stu, n);
        m = FinaMax(stu, n);
        printf("%s get the highest scholarship %d", (stu + m)->name, (stu + m)->scholarship);
        return 0;
    }
    
    int FinaMax(WIN* stu, int n)
    {
        int max = stu->scholarship;
        int maxi = 0;
        for (int i = 0; i < n; i++)
        {
            if ((stu + i)->scholarship > max)
            {
                max = (stu + i)->scholarship;
                maxi = i;
            }
        }
        return maxi;
    }
    
    void Input(WIN* stu, int n)
    {
        for (int i = 0; i < n; i++)
        {
            printf("Input name:");
            getchar();
            gets((stu + i)->name);
            printf("Input final score:");
            scanf("%d", &(stu + i)->finalScore);
            printf("Input class score:");
            scanf("%d", &(stu + i)->classScore);
            printf("Class cadre or not?(Y/N):");
            getchar();
            scanf("%c",&(stu + i)->work);
            printf("Students from the West or not?(Y/N):");
            getchar();
            scanf("%c", &(stu + i)->west);
            printf("Input the number of published papers:");
            scanf("%d", &(stu + i)->paper);
            (stu + i)->scholarship = 0;
            if ((stu + i)->finalScore > 80 && (stu + i)->paper >= 1)
                (stu + i)->scholarship += 8000;
            if ((stu+i)->finalScore>85 && (stu+i)->classScore>80)
                (stu + i)->scholarship += 4000;
            if ((stu+i)->finalScore>90)
                (stu + i)->scholarship += 2000;
            if ((stu+i)->finalScore>85 && (stu+i)->west == 'Y')
                (stu + i)->scholarship += 1000;
            if ((stu+i)->finalScore>80 && (stu+i)->work == 'Y')
                (stu + i)->scholarship += 850;
            printf("name:%s,scholarship:%d\n", (stu+i)->name ,(stu + i)->scholarship);
        }
    }
    

    3评选最牛群主v1.0

    # include<stdio.h>
    # include<math.h>
    # include<string.h>
    
    
    int main()
    {
        int n;
        char name[5];
        char ele[3][5] = { "tom", "jack", "rose" };
        int count[3] = { 0 };
        printf("Input the number of electorates:");
        scanf("%d", &n);
        getchar();
        for (int i = 0; i < n; i++)
        {
            printf("Input vote %d:", i+1);
            gets(name);
            if (strcmp(name, ele[0]) == 0)
                count[0]++;
            else if (strcmp(name, ele[1]) == 0)
                count[1]++;
            else if (strcmp(name, ele[2]) == 0)
                count[2]++;
        }
        printf("Election results:\n");
        printf("tom:%d\njack:%d\nrose:%d\n", count[0], count[1], count[2]);
        int max = count[0];
        int maxi = 0;
        for (int i = 1; i < 3; i++)
        {
            if (max < count[i])
            {
                maxi = i;
                max = count[i];
            }
        }
        printf("%s wins\n", ele[maxi]);
        return 0;
    }
    

    4星期判断

    #include<stdio.h>
    #include <string.h>
    
    int main()
    {
        char *week[7] = { "monday","tuesday","wednesday","thursday","friday","saturday","sunday"};
        char first;
        char second;
        int flag = 0;
        printf("please input the first letter of someday:\n");
        scanf(" %c", &first);
        first = tolower(first);
        switch (first)
        {
        case 'm':
            flag = 1;
            break;
        case 'w':
            flag = 3;
            break;
        case 'f':
            flag = 5;
            break;
        case 't':
            printf("please input second letter:\n");
            scanf(" %c", &second);
            //second = tolower(second);
            if (second == 'u')
                flag = 2;
            else if (second == 'h')
                flag = 4;
            else
                flag = 0;
            break;
        case 's':
            printf("please input second letter:\n");
            scanf(" %c", &second);
            //second = tolower(second);
            if (second == 'a')
                flag = 6;
            else if (second == 'u')
                flag = 7;
            else
                flag = 0;
            break;
        default:
            flag = 0;
            break;
        }
        if (flag != 0 && flag < 8)
            printf("%s\n", week[flag-1]);
        else
            printf("data error\n");
        return 0;   
    }
    

    相关文章

      网友评论

        本文标题:第12周编程题在线测试

        本文链接:https://www.haomeiwen.com/subject/xsienctx.html