#include
#include
#include
struct stu{
?int xuehao;
?char name[10];
?int eng;
?int math;
?int wuli;
?int cyuyan;
?struct stu *next;
};
int n;
static struct stu *head=NULL;
static struct stu *prev,*current;
void input(void)
{
?printf("請輸入學(xué)生人數(shù)\n");?
?scanf("%d",&n);
?printf("請輸入學(xué)生信息按照學(xué)號2021001開始 姓名 英語成績 數(shù)學(xué)成績 物理成績 c語言成績的格式\n");?
?for(int i=0;i
??? ?current=(struct stu*)malloc(sizeof(struct stu));
??? ?if(head==NULL)
??? ? ? ?head=current;
??? ?else prev->next=current;
??? ?current->next=NULL;
??? ?scanf("%d%s%d%d%d%d",¤t->xuehao,current->name,¤t->eng,¤t->math,¤t->wuli,¤t->cyuyan);
??? ?while(getchar()!='\n')
??? ? ? ?continue;
??? ?prev=current;
?}
?printf("完成了%d位同學(xué)的成績輸入\n",n);
}
void output(void)
{
?printf("%d位學(xué)生成績?nèi)缦耚n",n);?
?if(head==NULL)
?printf("0");
?current=head;
?while(current!=NULL)
?{
??? ?printf("%d %s %d %d %d %d\n",current->xuehao,current->name,current->eng,current->math,current->wuli,current->cyuyan);
??? ?current=current->next;
?}
}
void change(void)
{
?printf("請輸入你想改變的學(xué)生信息,按照格式:學(xué)號 數(shù)字 改變后內(nèi)容(其中數(shù)字0代表改姓名1代表英語以此類比直到數(shù)字4\n");
?current=head;
?int xuefen,m,name[10];
?scanf("%d",&xuefen);
?scanf("%d",&m);
?for(int i=0;i
??? ?current=current->next;
?}
?switch(m)
?{
??? ?case 0:scanf("%s",current->name);break;
??? ?case 1:scanf("%d",¤t->eng);break;
??? ?case 2:scanf("%d",¤t->math);break;
??? ?case 3:scanf("%d",¤t->wuli);break;
??? ?case 4:scanf("%d",¤t->cyuyan);break;
?}
?printf("%d %s %d %d %d %d\n",current->xuehao,current->name,current->eng,current->math,current->wuli,current->cyuyan);
?current=head;
?
}
void average(int n)
{
?printf("各科成績以及平均成績?nèi)缦?);?
?current=head;
?for(int i=0;i
??? ?printf("%d %s %.2f\n",current->xuehao,current->name,(float)(current->eng+current->math+current->wuli+current->cyuyan)/4);
??? ?current=current->next;
?}
}
void outevery(int n)
{
?printf("各科成績以,平均成績以及總成績?nèi)缦?);?
?current=head;
?for(int i=0;i
??? ?printf("%d %s %d %.2f\n",current->xuehao,current->name,current->eng+current->math+current->wuli+current->cyuyan,(float)(current->eng+current->math+current->wuli+current->cyuyan)/4);
??? ?current=current->next;
?}
}
int main(void)
{
?printf("請輸入你想實現(xiàn)的功能0退出1輸入成績2輸出成績3修改指定項目內(nèi)容4輸出平均成績5輸出總成績\n");?
?int choose;
?while(scanf("%d",&choose)!=0)
?{
??? ?if(choose==0)
??? ?{
??? ??? ?printf("程序執(zhí)行完畢,歡迎下次光臨!");?
??? ? ? ?return 0;
?}
??? ?switch(choose)
??? ?{
??? ??? ?case 1:input();break;
??? ??? ?case 2:output();break;
??? ??? ?case 3:change();break;
??? ??? ?case 4:average(n);break;
??? ??? ?case 5:outevery(n);break;
??? ?}
??? ?
?}
?current=head;
?while(current!=NULL)
?{
??? ?head=current->next;
??? ?free(current);
??? ?current=head;
?}
?return 0;
}
作為oj上的難題,寫完后真是心情舒暢
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧