第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獎學金發(fā)放

# 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;   
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 在C語言中,五種基本數(shù)據(jù)類型存儲空間長度的排列順序是: A)char B)char=int<=float C)ch...
    夏天再來閱讀 4,071評論 0 2
  • 位運算符: 位運算符只針對數(shù)字的二進制形式進行。 var v1 = 5; //這是10進制,二進制其實是:101,...
    定格r閱讀 814評論 0 0
  • 產(chǎn)品知識面考察 真題 例題分析 例題7.3 DAU代表 。 日用戶點擊量 月活躍用戶數(shù)量 日活躍用戶數(shù)量 網(wǎng)站...
    愛攝影的奧派閱讀 12,715評論 4 46
  • 一段緩慢的淡出切換, 黑色的夜,褪去外衣。 在知道晴朗還是陰霾之前, 灰的白,先蓋上心頭。 在知道喧鬧終究要到來之...
    li3wei閱讀 264評論 0 0
  • 安裝了Anaconda,在命令行,輸入python 出現(xiàn)Warning: This Python interpre...
    紅塵_漫步閱讀 15,191評論 1 2

友情鏈接更多精彩內(nèi)容