You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
3.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<stdio.h>
#include<string.h>
#define size 4
int main()
{
//前面需要输入学生信息的函数,此处我就瞎定义几个为了方便测试
//int sum();
void sequence();
int count();
struct Student
{
int class;//[size];
int number, score;
int ans;
int score1, score2, all_score;//三门成绩分别为scorescore1score2all_score为了求和
}Student[size + 1], temp;
Student[0].class = 11;
Student[1].class = 11;
Student[2].class = 12;
Student[0].number = 10001;
Student[1].number = 10002;
Student[2].number = 10004;
Student[0].score = 90; Student[0].score1 = 90; Student[0].score2 = 90;
Student[1].score = 83; Student[1].score1 = 84; Student[1].score2 = 85;
Student[2].score = 83; Student[2].score1 = 70; Student[2].score2 = 90;
int size1;
size1 = count(Student[size-1].number);
//输入的部分替换为输入函数
/*scanf("%d%d%d%d", &class[0], &class[1], &class[2], &class[3]);
scanf("%d%d%d%d", &number[0], &number[1], &number[2], &number[3]);
scanf("%d%d", &all_score[0], &all_score[1]);*/
printf("please enter the information:");
//上面是我写的输入,下面是插入函数的部分
scanf_s("%d", &Student[size - 1].class);
scanf_s("%d", &Student[size - 1].number);
int c = Student[size - 1].number;//记住学生学号
//scanf_s("%d", &Student[size-1].class);
scanf_s("%d%d%d", &Student[size - 1].score, &Student[size - 1].score1, &Student[size - 1].score2); //&Student[size - 1].all_score);//输入学生信息
/*for (int count1 = 0; count1 < size; count1++)
{
printf("%d %d %d %d %d", Student[count1].class, Student[count1].number, Student[count1].score, Student[count1].score1, Student[count1].score2);
if (c == Student[count1].number)//显示插入的学生
{
printf(" inserted");
}
printf("\n");
}*/
//根据班级排序
int count2 = 0, count3 = 0;
for (count2 = 0; count2 < size; count2++)
{
for (count3 = count2 + 1; count3 < size; count3++)
{
if (Student[count2].class > Student[count3].class )
{
temp = Student[count2];
Student[count2] = Student[count3];
Student[count3] = temp;
}
}
}
for (int count4 = 0; count4 < size; count4++)
{
Student[count4].all_score = Student[count4].score+Student[count4].score1 + Student[count4].score2;
}
//同班根据成绩排序
count2=0, count3=0;
for (count2 = 0; count2 < size; count2++)
{
for (count3 = count2 + 1; count3 < size; count3++)
{
if (Student[count2].class == Student[count3].class && Student[count2].all_score < Student[count3].all_score)
{
temp = Student[count2];
Student[count2] = Student[count3];
Student[count3] = temp;
}
}
}
for (int count1 = 0; count1 < size; count1++)
{
printf("%d %d %d %d %d", Student[count1].class, Student[count1].number, Student[count1].score, Student[count1].score1, Student[count1].score2);
if (c == Student[count1].number)//显示插入的学生
{
printf(" inserted");
}
printf("\n");
}
return 0;
}
//排序函数
void sequence(int arr[size])
{
int temp;
for (int count1 = 1; count1 <= size; count1++)
{
for (int count2 = 1; count2 <= size - count1; count2++)
{
if (arr[count2 - 1] > arr[count2])
{
temp = arr[count2];
arr[count2] = arr[count2 + 1];
arr[count2 + 1] = temp;
}
}
}
}
//求和函数
int sum(int x, int y, int z)
{
int ans;
ans = x + y + z;
return ans;
}
//为了定义数组的长度,所以写了一个检测的函数,即把size改为size1+1
//size1是数组真实的长度
//size是我为了方便定义的全局变量
int count(int arr[])
{
int len;
len = sizeof(arr) / sizeof(arr[0]);
return len;
}
/*
//交换函数
void change(int number1,int number2,int real_change1,int real_change2)
{
int temp;
if (number1 > number2)
{
temp = real_change1;
real_change1 = real_change2;
real_change2 = temp;
}
}
*/