第12周编程题在线测试

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;   
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 在C语言中,五种基本数据类型存储空间长度的排列顺序是: A)char B)char=int<=float C)ch...
    夏天再来阅读 9,081评论 0 2
  • 位运算符: 位运算符只针对数字的二进制形式进行。 var v1 = 5; //这是10进制,二进制其实是:101,...
    定格r阅读 4,073评论 0 0
  • 产品知识面考察 真题 例题分析 例题7.3 DAU代表 。 日用户点击量 月活跃用户数量 日活跃用户数量 网站...
    爱摄影的奥派阅读 14,278评论 4 46
  • 一段缓慢的淡出切换, 黑色的夜,褪去外衣。 在知道晴朗还是阴霾之前, 灰的白,先盖上心头。 在知道喧闹终究要到来之...
    li3wei阅读 1,661评论 0 0
  • 安装了Anaconda,在命令行,输入python 出现Warning: This Python interpre...
    红尘_漫步阅读 15,151评论 1 2

友情链接更多精彩内容