ADD file via upload

main
p62jhspgx 1 year ago
parent eaf8a0de3e
commit 4db13d5492

114
t5.c

@ -0,0 +1,114 @@
#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 delete_array();
void Sort();
void print();
int main()
{
delete_array();
}
void delete_array()
{
char ans, info_delete[20];
int l, kk = -1;
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_delete);
for (int i = 0; i < 3; i++)
{
if (strcmp(name[i], info_delete) == 0)
{
kk = i;
}
else if (strcmp(num[i], info_delete) == 0)
{
kk = i;
}
}
if (kk == -1)
{
print();
return;
}
Sort();
for (int i = 0; i < 3; i++)
{
if (strcmp(info_delete, name[i]) && strcmp(info_delete, num[i]))
{
printf("%s %d %s %.1f %.1f %.1f\n", num[i], Class[i], name[i], Maths[i], Physics[i], English[i]);
}
}
getchar();
printf("Are you sure(yes/no)?\n");
scanf("%c", &ans);
if (ans == 'n')
{
print();
return;
}
else if (ans == 'y')
{
return;
}
}
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);
}
}
}
}
}
void print()
{
Sort();
for (int i = 0; i < 3; i++)
{
printf("%s %d %s %.1f %.1f %.1f\n", num[i], Class[i], name[i], Maths[i], Physics[i], English[i]);
}
}
Loading…
Cancel
Save