40分求助,2re1wa
查看原帖
40分求助,2re1wa
808409
Carriechenchen楼主2022/10/20 16:26

#include<stdio.h>
#include<math.h>
#include<string.h>
int judge(int a, int b, int distance);
struct stu
{
	int numble;
	int ChineseScore;
	int MathScore;
	int EnglishScore;
	int sum;
	char name[100];
};
struct stu score[2500];
struct student
{
    char name1[100];
    char name2[100];
};
struct student cp[2500];
int main()
{
	int N = 0;
	int count = 0;
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
	{
		scanf("%s%d%d%d",score[i].name,&score[i].ChineseScore,//输入名字
			&score[i].MathScore, &score[i].EnglishScore);
		score[i].sum = score[i].ChineseScore + score[i].MathScore + score[i].EnglishScore;
	}
	for (int i = 0; i < N; i++)
	{
		for (int j = i+1; j < N; j++)
		{
			int flag1 = 1,flag2=1,flag3=1,flag4=1;
			flag1 = judge(score[i].ChineseScore, score[j].ChineseScore, 5);
			flag2 = judge(score[i].MathScore, score[j].MathScore, 5);
			flag3 = judge(score[i].EnglishScore, score[j].EnglishScore, 5);
			flag4 = judge(score[i].sum, score[j].sum, 10);
			if (flag1&&flag2&&flag3&&flag4)
            {
                int sign=strcmp(score[i].name,score[j].name);
                    if (sign>0)//i在后面
                {
                    strcpy(cp[count].name1,score[j].name);
                    strcpy(cp[count].name2,score[i].name);
                }
                    else if (sign<0)//i在前面
                {
                    strcpy(cp[count].name1,score[i].name);
                    strcpy(cp[count].name2,score[j].name);
                }
                count++;

            }

		}
	}
	for(int i=0;i<count;i++)
    {
        for(int j=0;j<count-i-1;j++)
        {
            if(strcmp(cp[j].name1,cp[j+1].name1)>0)
            {
                char temp1[100];//排序
                char temp2[100];
                 strcpy(temp1,cp[j].name1);
                 strcpy(cp[j].name1,cp[j+1].name1);
                 strcpy(cp[j+1].name1,temp1);
                 strcpy(temp2,cp[j].name2);
                 strcpy(cp[j].name2,cp[j+1].name2);
                 strcpy(cp[j+1].name2,temp2);
            }
            else if(strcmp(cp[j].name1,cp[j+1].name1)==0)
            {
                if(strcmp(cp[j].name2,cp[j+1].name2)>0)
                {
                     char temp1[100];//排序
                     char temp2[100];
                     strcpy(temp1,cp[j].name1);
                     strcpy(cp[j].name1,cp[j+1].name1);
                     strcpy(cp[j+1].name1,temp1);
                     strcpy(temp2,cp[j].name2);
                     strcpy(cp[j].name2,cp[j+1].name2);
                     strcpy(cp[j+1].name2,temp2);
                }

            }
        }
    }
    for(int i=0;i<count;i++)
    {
        printf("%s %s\n",cp[i].name1,cp[i].name2);
    }
	return 0;
}
int judge(int a, int b, int distance)
{
	int flag = 1;
	if (abs(a - b) > distance)
		flag = 0;
	return flag;
}

40分求助,想知道哪里错了

2022/10/20 16:26
加载中...