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.
96 lines
2.3 KiB
96 lines
2.3 KiB
1 year ago
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
int Class[3];
|
||
|
char name[3][20], num[3][10];
|
||
|
float Maths[3], Physics[3], English[3], sum[3];
|
||
|
|
||
|
void Swap(int k);
|
||
|
void change_array();
|
||
|
void Sort();
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
change_array();
|
||
|
}
|
||
|
void change_array()
|
||
|
{
|
||
|
int k = -1;
|
||
|
char info_change[20];
|
||
|
for (int i = 0; i < 3; i++)
|
||
|
{
|
||
|
scanf("%s%d%s%f%f%f", &num[i], &Class[i], name[i], &Maths[i], &Physics[i], &English[i]);
|
||
|
sum[i] = Maths[i] + Physics[i] + English[i];
|
||
|
}
|
||
|
getchar();
|
||
|
scanf("%s", info_change);
|
||
|
for (int i = 0; i < 3; i++)
|
||
|
{
|
||
|
if (strcmp(num[i], info_change) == 0)
|
||
|
{
|
||
|
k = i;
|
||
|
getchar();
|
||
|
scanf("%d%s%f%f%f", &Class[i], name[i], &Maths[i], &Physics[i], &English[i]);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
Sort();
|
||
|
for (int i = 0; i < 3; i++)
|
||
|
{
|
||
|
if (i && Class[i] == Class[i - 1])
|
||
|
{
|
||
|
printf(" %s %s %.1f %.1f %.1f", num[i], name[i], Maths[i], Physics[i], English[i]);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("%d %s %s %.1f %.1f %.1f", Class[i], num[i], name[i], Maths[i], Physics[i], English[i]);
|
||
|
}
|
||
|
if (k == i)
|
||
|
{
|
||
|
printf(" modified");
|
||
|
}
|
||
|
printf("\n");
|
||
|
}
|
||
|
}
|
||
|
void Swap(int k)
|
||
|
{
|
||
|
int Class0 = Class[k];
|
||
|
char name0[20], num0[10];
|
||
|
strcpy(name0, name[k]);
|
||
|
strcpy(num0,num[k]);
|
||
|
float Maths0 = Maths[k], Physics0 = Physics[k], English0 = English[k], sum0 = sum[k];
|
||
|
Class[k] = Class[k - 1];
|
||
|
strcpy(name[k], name[k - 1]);
|
||
|
strcpy(num[k], num[k - 1]);
|
||
|
Maths[k] = Maths[k - 1];
|
||
|
Physics[k] = Physics[k - 1];
|
||
|
English[k] = English[k - 1];
|
||
|
sum[k] = sum[k - 1];
|
||
|
Class[k - 1] = Class0;
|
||
|
strcpy(name[k - 1], name0);
|
||
|
strcpy(num[k - 1], num0);
|
||
|
Maths[k - 1] = Maths0;
|
||
|
Physics[k - 1] = Physics0;
|
||
|
English[k - 1] = English0;
|
||
|
sum[k - 1] = sum0;
|
||
|
}
|
||
|
void Sort()
|
||
|
{
|
||
|
for (int i = 0; i < 3; i++)
|
||
|
{
|
||
|
for (int j = 2; j > i; j--)
|
||
|
{
|
||
|
if (Class[j] < Class[j - 1])
|
||
|
{
|
||
|
Swap(j);
|
||
|
}
|
||
|
else if(Class[j] == Class[j - 1])
|
||
|
{
|
||
|
if (sum[j] > sum[j - 1])
|
||
|
{
|
||
|
Swap(j);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|