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.
174 lines
2.8 KiB
174 lines
2.8 KiB
#include <stdio.h>
|
|
#include <string.h>
|
|
int cnt=0;
|
|
struct student{
|
|
int clas;
|
|
char id[20],name[20];
|
|
double score1,score2,score3,total;
|
|
}s[10];
|
|
|
|
void input(){
|
|
while(1){
|
|
printf("Id ");
|
|
scanf("%s",s[cnt].id);
|
|
printf("class ");
|
|
scanf("%d",&s[cnt].clas);
|
|
printf("name ");
|
|
scanf("%s",s[cnt].name);
|
|
printf("score1 ");
|
|
scanf("%lf",&s[cnt].score1);
|
|
printf("score2 ");
|
|
scanf("%lf",&s[cnt].score2);
|
|
printf("score3 ");
|
|
scanf("%lf",&s[cnt].score3);
|
|
s[cnt].total=s[cnt].score1+s[cnt].score2+s[cnt].score3;
|
|
cnt++;
|
|
printf("continue?\n");
|
|
char ans[10];
|
|
scanf("%s",ans);
|
|
if(strcmp(ans,"no")==0) break;
|
|
}
|
|
}
|
|
|
|
void del(){
|
|
while(1){
|
|
char str[20];
|
|
scanf("%s",str);
|
|
int i=find(str);
|
|
if(i!=-1){
|
|
for(;i<cnt-1;i++){
|
|
s[i]=s[i+1];
|
|
}
|
|
cnt--;
|
|
}
|
|
for(i=0;i<cnt;i++) output(i);
|
|
printf("continue?\n");
|
|
char ans[10];
|
|
scanf("%s",ans);
|
|
if(strcmp(ans,"no")==0) break;
|
|
}
|
|
}
|
|
|
|
int find(char str[]){
|
|
int i;
|
|
for(i=0;i<cnt;i++){
|
|
if(strcmp(s[i].id,str)==0||strcmp(s[i].name,str)==0){
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
void select(){
|
|
while(1){
|
|
int i,flag=0;
|
|
char str[20];
|
|
scanf("%s",str);
|
|
if(strlen(str)==2){
|
|
int clas=10*(str[0]-'0')+str[1]-'0';
|
|
for(i=0;i<cnt;i++){
|
|
if(s[i].clas==clas){
|
|
flag=1;
|
|
output(i);
|
|
}
|
|
}
|
|
}
|
|
else{
|
|
for(i=0;i<cnt;i++){
|
|
if(strcmp(s[i].id,str)==0){
|
|
flag=1;
|
|
output(i);
|
|
}
|
|
}
|
|
}
|
|
if(!flag) printf("there is no eligible student\n");
|
|
printf("continue?\n");
|
|
char ans[10];
|
|
scanf("%s",ans);
|
|
if(strcmp(ans,"no")==0) break;
|
|
}
|
|
}
|
|
|
|
void order(){
|
|
int i,j;
|
|
for(i=0;i<cnt-1;i++){
|
|
for(j=0;j<cnt-i-1;j++){
|
|
if(s[j].clas>s[j+1].clas||(s[j].clas==s[j+1].clas&&s[j].total<s[j+1].total)){
|
|
struct student t;
|
|
t=s[j];
|
|
s[j]=s[j+1];
|
|
s[j+1]=t;
|
|
}
|
|
}
|
|
}
|
|
for(i=0;i<cnt;i++) output(i);
|
|
}
|
|
|
|
void output(int i){
|
|
printf("%s,%d,%s,%.1f,%.1f,%.1f,%.1f\n",s[i].id,s[i].clas,s[i].name,s[i].score1,s[i].score2,s[i].score3,s[i].total);
|
|
}
|
|
|
|
int main(){
|
|
int opt,i;
|
|
while(1){
|
|
printf("1.input\n");
|
|
printf("2.delete\n");
|
|
printf("3.select\n");
|
|
printf("4.order\n");
|
|
printf("5.output\n");
|
|
printf("6.quit\n");
|
|
printf("please input your option\n");
|
|
scanf("%d",&opt);
|
|
if(opt==1) input();
|
|
else if(opt==2) del();
|
|
else if(opt==3) select();
|
|
else if(opt==4) order();
|
|
else if(opt==5){
|
|
for(i=0;i<cnt;i++) output(i);
|
|
}
|
|
else if(opt==6) break;
|
|
}
|
|
return 0;
|
|
}
|
|
//1
|
|
//1001
|
|
//11
|
|
//zhang
|
|
//99.5
|
|
//88.5
|
|
//89.5
|
|
//yes
|
|
//1002
|
|
//22
|
|
//li
|
|
//77.9
|
|
//56.5
|
|
//87.5
|
|
//yes
|
|
//1003
|
|
//11
|
|
//wang
|
|
//92.5
|
|
//99.0
|
|
//60.5
|
|
//no
|
|
//2
|
|
//1002
|
|
//no
|
|
//3
|
|
//1001
|
|
//yes
|
|
//11
|
|
//no
|
|
//1
|
|
//1002
|
|
//22
|
|
//li
|
|
//77.9
|
|
//56.5
|
|
//87.5
|
|
//no
|
|
//4
|
|
//5
|
|
//6
|