c语言编程:歌唱比赛评委评分系统

c语言编程:歌唱比赛评委评分系统,第1张

#include <stdio.h>

#include<string.h>

void main()

{

int i,j,m,n

float num,xgrade[100],max,min,pgrade[100],pdis[100]

char str[10],xname[100][10],pname[100][10]

printf("请输入评委人数:")

scanf("%d",&m)

printf("\n请分别输入评委姓名:\n")

for(i=0i<mi++)

{

scanf("%s",&pname[i])//评委姓名

pgrade[i]=0//评委给的分

pdis[i]=0//评委给分和最后结果的差距

}

printf("\n请输入选手人数:")

scanf("%d",&n)

printf("\辩睁n请分别输入选手姓名:\n")

for(i=0i<ni++)

{

scanf("%s",&xname[i])//选手姓名

xgrade[i]=0//选手成绩

}

for(i=0i<ni++)

{

max=0min=10//评委给选手的最大最小成绩

printf("\n请给选手%s打分!",xname[i])

for(j=0j<mj++)

{

printf("\n%s老师给的分数为:",pname[j])

scanf("%f",&pgrade[j])

xgrade[i]+=pgrade[j]//加到该选手的总分数中

if(max<pgrade[j])

max=pgrade[j]

if(min>pgrade[j])

min=pgrade[j]

}

xgrade[i]=(xgrade[i]-max-min)/(m-2)//最后成绩为总成绩-最高分-最低分,然后平均

for(j=0j<mj++)//算出每个评委本次评袭雀分和最终成绩的差,加到pdis中保存起来

{

pdis[j]+=pgrade[j]>xgrade[i]?(pgrade[j]-xgrade[i]):(xgrade[i]-pgrade[j])

}

}

for(i=0i<n-1i++)

for(j=0j<n-1-ij++)

if(xgrade[j]<xgrade[j+1])

{

strcpy(str,xname[j])

strcpy(xname[j],xname[j+1])

strcpy(xname[j+1],str)

num=xgrade[j]

xgrade[j]=xgrade[j+1]

xgrade[j+1]=num

}

printf("\n选手按名次排名为:\n")

printf("选手名\t得分\n")

for(i=0i<ni++)

printf("%s\t%f\n",xname[i],xgrade[i])

for(i=0i<m-1i++)

for(j=0j<m-1-ij++)

if(pdis[j]>pdis[j+1])

{

strcpy(str,pname[j])

strcpy(pname[j],pname[j+1])

strcpy(pname[j+1],str)

num=pdis[j]

pdis[j]=pdis[j+1]

pdis[j+1]=num

}

printf("\n评委按名次排名为:\n")

printf("评委名\t差分拍灶早\n")

for(i=0i<mi++)

printf("%s\t%f\n",pname[i],pdis[i])

}

vae.la

#include <stdio.h>

int main()

{

    int N, 升埋和a, max, min, sum,i

    scanf("%d",&N)

   吵盯 scanf("%d",&a)

    max=min=sum=a

    for(i = 1 i < N i ++)

    {

        scanf("%d",&a)

  液枝      if(a>max) max=a

        if(a<min) min=a

        sum+=a

    }

    sum-=max+min

    printf("%.2f\n", (float)sum/(N-2))

    return 0

}

#include <stdio.h>

#include <string.h>

#define Total 10

struct People {

    int ID

    char name[20]

    double score[10]

    double final_score

    int rank

} people[Total]

void inputInfo()

{

    printf("Please input data:\n")

    for (int i = 0 i < Total i ++) {

        scanf("%d", &people[i].ID)

        getchar()

        scanf("%s", people[i].name)

        scanf("%lf", &people[i].score[0])

        scanf("%lf", &people[i].score[1])

        scanf("%lf", &people[i].score[2])

        scanf("%lf", &people[i].score[3])

        scanf("%lf", &people[i].score[4])

        scanf("%lf", &people[i].score[5])

        scanf("%lf", &people[i].score[6])

        scanf("%lf", &people[i].score[7])

        scanf("%lf", &people[i].score[8])

        scanf("%lf", &people[i].score[9])

        people[i].final_score = 0.0

        people[i].rank = i + 1

    }

}

void calculateScore()

{

    for (int i = 0 i < Total i ++) {

        double max = people[i].score[0]

        double min = people[i].score[0]

        for (int j = 饥漏0 j < 10 j ++) {

            people[i].final_score += people[i].score[j]

            if (people[i].score[j] > max)

                max = people[i].score[j]

            if (people[i].score[j] < min)

                min = people[i].score[j]

        }

        people[i].final_score = people[i].final_score - max - min

        people[i].final_score /= 8

    }

    printf("Calculate complete!\n")

}

void sort()

{

    calculateScore()

    for (int i = 0 i < Total - 1 i ++) {

        for (int j = 0 j < Total - 1 - i j ++) {

            if (people[j].final_score < people[j + 1].final_score && people[j].rank < people[j + 1].rank) {

                struct People tmp = people[j]

                people[j] = people[j + 1]

                people[j + 1] = tmp

                people[j].rank = j + 1

                people[j + 1].rank = j + 2

            }

            if (people[j].final_score > people[j + 1].final_score && people[j].rank > people[j + 1].rank) {

                struct People tmp = people[j]

                people[j] = people[j + 1]

                people[j + 1] = tmp

                people[j].rank = j + 1

                people[j + 1].rank = j + 2

            }

        }

    }

    printf("Sort complete!\n")

}

void searchByID()

{

    int ID

    printf("Please input the ID of the person:")

    scanf("%d", &ID)

    for (int i = 0 i < Total i ++) {

        if (people[i].ID == ID) {

            printf("-----------------------------------------\n")

            printf("--  You are viewing the person No.%d     \n", ID)

            printf("--  The final score is: %.2lf  模高          \n", people[i].final_score)

      旦肢尺      printf("--  The rank is: %d                      \n", people[i].rank)

            printf("-----------------------------------------\n")

            return

        }

    }

}

void searchByName()

{

    char name[20]

    printf("Please input the name of the person:")

    scanf("%s", name)

    for (int i = 0 i < Total i ++) {

        if (strcmp(people[i].name, name) == 0) {

            printf("-----------------------------------------------\n")

            printf("--  You are viewing the person: %s       \n", name)

            printf("--  The final score is: %.2lf            \n", people[i].final_score)

            printf("--  The rank is: %d                      \n", people[i].rank)

            printf("-----------------------------------------------\n")

            return

            

        }

    }

}

void quertPeople()

{

    int choice

    printf("Do you want to search by ID or by name? 0-ID,1-name:")

    scanf("%d", &choice)

    if (choice == 0)

        searchByID()

    if (choice == 1)

        searchByName()

}

void menu()

{

    printf("-------------------------------------------------\n")

    printf("--  1 - input data                             --\n")

    printf("--  2 - calculate the score and sort the data  --\n")

    printf("--  3 - search for person                      --\n")

    printf("--  0 - exit                                   --\n")

    printf("-------------------------------------------------\n")

}

int main() {

    int choice

    menu()

    scanf("%d", &choice)

    while (choice != 0){

        switch (choice) {

            case 1:

                inputInfo()

                break

            case 2:

                sort()

                break

            case 3:

                quertPeople()

                break

            default:

                break

        }

        menu()

        scanf("%d", &choice)

    }

    return 0

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12480066.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存