c語(yǔ)言實(shí)現(xiàn)足球比賽積分統(tǒng)計(jì)系統(tǒng)
本文實(shí)例為大家分享了c語(yǔ)言實(shí)現(xiàn)足球比賽積分統(tǒng)計(jì)系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
/* 足球比賽積分統(tǒng)計(jì)系統(tǒng) ? ?作者:施瑞文 ? ?時(shí)間:2018.2 */? ?//為簡(jiǎn)單化,這里沒(méi)有加上文件的操作? #include <stdio.h> #include <stdlib.h> #include <string.h> #include<windows.h> #include<conio.h> #define LEN sizeof(match) typedef struct football { ?? ?char name[20];//[足球]隊(duì)名 ?? ?int num[4];//num[0]為單支球隊(duì)需比賽場(chǎng)數(shù), num[1]為贏場(chǎng)數(shù),num[2]為平場(chǎng)數(shù),num[3]為負(fù)場(chǎng)數(shù) ?? ?int goal;//進(jìn)球數(shù) ?? ?int lose;//失球數(shù) ?? ?int integral;//積分 ?? ?int pure;//凈勝球 ?? ?struct football *next;? }match; void menu();//聲明菜單函數(shù)? match *creat();//輸入球隊(duì)信息? void print(match *head);//排序? match *Add(match *head);//增加球隊(duì)信息 match *Amend(match *head);//修改球隊(duì)信息? match *Del(match *head);//刪除球隊(duì)信息? void End();//退出該軟件? ? int n=0;//記錄節(jié)點(diǎn)長(zhǎng)度? match *p2; ? void toxy(int x, int y)//將光標(biāo)移動(dòng)到X,Y坐標(biāo)處 { ? COORD pos = { x , y }; ? HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE); ? SetConsoleCursorPosition(Out, pos); } ? ? void menu() { ?? ?system("cls");//清屏? ?? ?system("color 72");//顏色? ?? ?toxy(30,6); ?? ?printf("--------------------MENU-----------------------\n"); ?? ?toxy(30,8); ?? ?printf("| ?1. ? Record the information of this match ?|\n"); ?? ?toxy(30,10); ?? ?printf("| ?2. ? Add the information of this match ? ? |\n"); ?? ?toxy(30,12); ?? ?printf("| ?3. ? Check the information of this match ? |\n"); ?? ?toxy(30,14); ?? ?printf("| ?4. ? delete the information of the match ? |\n"); ?? ?toxy(30,16); ?? ?printf("| ?5. ? Amend the information of the match ? ?|\n"); ?? ?toxy(30,18); ?? ?printf("| ?6. ? End this operation ? ? ? ? ? ? ? ? ? ?|\n"); ?? ?toxy(30,20); ?? ?printf("-----------------------------------------------\n"); ?? ?toxy(30,22); ?? ?printf("What are you want to do ? Input please:"); } ? match *creat() { ?? ?system("cls");//清屏? ?? ?system("color 74");//顏色? ?? ?int t,n=0; ?? ?match *head,*p1; ?? ?p2=p1=(match *)malloc(LEN); ?? ?head=NULL; ?? ? ?? ?/*錄入足球隊(duì)名,比賽場(chǎng)數(shù),得、失 球數(shù)和進(jìn)球積分*/? ?? ? ?? ?/*輸入第一個(gè)節(jié)點(diǎn)數(shù)據(jù) */ ? ?? ?printf("Enter the total number of the football teams:");//參賽的球隊(duì)數(shù)量? ?? ?scanf("%d",&t); ?? ? ?? ? ?? ? ?? ?while(n!=t) ?? ?{ ?? ??? ?n++;? ?? ??? ?printf("the name of team %d :",n);//球隊(duì)名? ?? ? ? ?scanf("%s",p1->name); ?? ? ?? ? ? ?printf("team %d win round(s):",n);//該球隊(duì)贏局場(chǎng)數(shù)? ?? ? ? ?scanf("%d",&p1->num[1]); ?? ? ?? ? ? ?printf("team %d draw round(s):",n);//該球隊(duì)平局場(chǎng)數(shù)? ?? ? ? ?scanf("%d",&p1->num[2]); ?? ? ? ?printf("team %d goal:",n); ?? ? ? ?scanf("%d",&p1->goal); ?? ? ? ?printf("team %d lose:",n); ?? ? ? ?scanf("%d",&p1->lose); ?? ? ? ?p1->integral=p1->num[1]*2+p1->num[2]; ?? ? ? ?p1->pure=p1->goal-p1->lose; ?? ??? ?if(n==1) ?? ??? ?{ ?? ??? ??? ?head=p1; ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?p2->next=p1; ?? ??? ??? ?p2=p1; ?? ??? ?} ?? ??? ?p1=(match *)malloc(LEN); ?? ?} ?? ?p2->next=NULL; ?? ?return head; } ? match *Add(match *head)//增加球隊(duì)? { ?? ?system("cls");//清屏? ?? ?system("color 72");//顏色? ?? ?match *p,*q,*newhead; ?? ?int x,y=0; ?? ?newhead=NULL; ?? ?p=q=(match *)malloc(LEN); ?? ?printf("How many teams you want to add?Input please:"); ?? ?scanf("%d",&x); ?? ?while(y!=x) ?? ?{ ?? ??? ?y++; ?? ??? ?printf("the name of team %d :",y);//球隊(duì)名? ?? ? ? ?scanf("%s",p->name); ?? ? ?? ? ? ?printf("team %d win round(s):",y);//該球隊(duì)贏局場(chǎng)數(shù)? ?? ? ? ?scanf("%d",&p->num[1]); ?? ? ?? ? ? ?printf("team %d draw round(s):",y);//該球隊(duì)平局場(chǎng)數(shù)? ? ? ? ? scanf("%d",&p->num[2]); ?? ? ? ?printf("the number of team %d goal:",y); ?? ? ? ?scanf("%d",&p->goal); ?? ? ? ?printf("the number of team %d lose:",y); ?? ? ? ?scanf("%d",&p->lose); ?? ? ? ?p->integral=p->num[1]*2+p->num[2]; ?? ? ? ?p->pure=p->goal-p->lose; ?? ? ? ?if(y==1) ?? ? ? ?{ ?? ? ? ??? ?newhead=p; ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?q->next=p; ?? ??? ??? ?q=p; ?? ??? ?} ?? ??? ?p=(match *)malloc(LEN); ?? ?} ?? ?q->next=NULL; ?? ?p2->next=newhead;//讓新增加的信息接入原有鏈表的后面? ?? ?return head; }? ? ? match *Amend(match *head)//修改信息? { ?? ?system("cls"); ?? ?system("color 72"); ?? ?do{ ?? ??? ?match *p=head; ?? ??? ?char name[10]; ?? ??? ?printf("Please input the team's name which you want to modify:"); ?? ??? ?gets(name); ?? ??? ?while(p!=NULL&&strcmp(p->name,name)!=0) ?? ??? ?{ ?? ??? ??? ?p=p->next; ?? ??? ?} ?? ??? ?if(p!=NULL) ?? ??? ?{ ?? ??? ??? ?toxy(25,4);? ?? ??? ??? ?printf("team_name ? ?win ? ? ?draw ? ? ?goal ? ? lose ? ? integral\n"); ?? ??? ??? ?toxy(25,6); ?? ??? ??? ?printf("|%3s%10d%10d%10d%10d%10d|\n",p->name,p->num[1],p->num[2],p->goal,p->lose,p->integral); ?? ??? ??? ?printf("Enter the new information please;\n"); ?? ??? ??? ?printf("the name of new team :");//球隊(duì)名? ?? ??? ? ? ?scanf("%s",p->name); ?? ??? ? ?? ??? ? ? ?printf("team win round(s):");//該球隊(duì)贏局場(chǎng)數(shù)? ?? ??? ? ? ?scanf("%d",&p->num[1]); ?? ??? ? ?? ??? ? ? ?printf("team ?draw round(s):");//該球隊(duì)平局場(chǎng)數(shù)? ?? ? ? ? ? ?scanf("%d",&p->num[2]); ?? ??? ? ? ?printf("the number of new team's goal:"); ?? ??? ? ? ?scanf("%d",&p->goal); ?? ??? ? ? ?printf("the number of ?new team's lose:"); ?? ??? ? ? ?scanf("%d",&p->lose); ?? ??? ? ? ?p->integral=p->num[1]*2+p->num[2]; ?? ??? ? ? ?p->pure=p->goal-p->lose; ?? ??? ? ? ?break; ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?printf("Input error!Please input again:"); ?? ??? ?} ? ? }while(1); ?? ?return head; } ? ? match *Del(match *head)//刪除信息? { ?? ?system("cls");//清屏? ?? ?do{ ?? ? ? match *p=head,*pre=NULL;//pre是p的前驅(qū)結(jié)點(diǎn)? ?? ? ? char name[10]; ?? ? ? printf("Please input the team's name which you want to delete;"); ?? ? ? gets(name); ?? ? ? while(p!=NULL&&strcmp(p->name,name)!=0) ?? ? ? { ?? ??? ? ? pre=p; ?? ??? ? ?p=p->next; ?? ? ? } ?? ? ? if(p!=NULL) ?? ? ? { ?? ? ? ? ? if(pre==NULL) ?? ??? ? ? { ?? ??? ? ? ?? ? head=p->next; ?? ??? ? ? } ?? ??? ? ? else ?? ??? ? ? { ?? ??? ? ?? ? ?pre->next=p->next; ?? ??? ? ? }?? ? ?? ??? ? ? free(p); ?? ??? ? ? break; ?? ? ? ?} ?? ? ? ?else ?? ? ? ?{ ?? ??? ? ? printf("Input error!Please input again:"); ?? ? ? ?} ? ? ?}while(1); ?? ?return head; } ? void End() { ?? ?system("cls"); ?? ?system("color 74"); ?? ?toxy(20,10); ?? ?printf("Thanks for your using!^-^"); ?? ?exit(0);//退出? ?? ?getch(); } ? ? void print(match *head) { ?? ?system("cls"); ?? ?system("color 74"); ?? ?match *p,*q,t1,t2,t3,*pt; ? ? for(p=head;p!=NULL;p=p->next)//球隊(duì)排序,冒泡法排序 ,關(guān)于鏈表的排序有點(diǎn)小復(fù)雜哦~? ?? ?{ ?? ??? ? ?? ??? ?for(q=p->next;q!=NULL;q=q->next) ? ? //這里有3重排序? ?? ??? ?{ ?? ??? ??? ? ?? ??? ??? ?if(p->integral<q->integral) ?? ??? ??? ?{ ?? ??? ??? ??? ?t1=*p; ?? ??? ??? ??? ?*p=*q; ?? ??? ??? ??? ?*q=t1;?? ? ?? ??? ??? ??? ?pt=p->next; ?? ??? ??? ??? ?p->next=q->next; ?? ??? ??? ??? ?q->next=pt; ?? ??? ??? ?} ?? ??? ??? ?else if(p->integral==q->integral) ?? ??? ??? ?{ ?? ??? ??? ??? ?if(p->pure<q->pure) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?t2=*p; ?? ??? ??? ??? ??? ?*p=*q; ?? ??? ??? ??? ??? ?*q=t2; ?? ??? ??? ??? ??? ?pt=p->next; ?? ??? ??? ??? ? ? ?p->next=q->next; ?? ??? ??? ??? ? ? ?q->next=pt; ?? ??? ??? ??? ?} ?? ??? ??? ??? ?else if(p->pure==q->pure) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?if(p->goal<q->goal) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?t3=*p; ?? ??? ??? ??? ??? ??? ?*p=*q; ?? ??? ??? ??? ??? ??? ?*q=t3; ?? ??? ??? ??? ??? ??? ?pt=p->next; ?? ??? ??? ??? ? ? ? ? ?p->next=q->next; ?? ??? ??? ??? ? ? ? ? ?q->next=pt; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?} ?? ??? ??? ?} ?? ??? ?} ?? ?} ?? ?p=head;//重新讓p指向第一個(gè)結(jié)點(diǎn)? ?? ?toxy(20,4); ?? ?printf("--------------------the football match imformation----------------------\n"); ?? ?toxy(20,6); ?? ?printf("team_name ? ?win ? ? ?draw ? ? ?goal ? ? lose ? ? integral\n"); ?? ?int m=8; ?? ??? ?while(p!=NULL) ?? ??? ?{ ?? ??? ??? ?toxy(20,m); ?? ??? ??? ?printf("|%3s%10d%10d%10d%10d%10d|\n",p->name,p->num[1],p->num[2],p->goal,p->lose,p->integral); ?? ??? ??? ?p=p->next; ?? ??? ??? ?m+=2; ?? ??? ?} ?? ??? ?printf("\nPlease press any key return to MENU. "); ?? ??? ?getch(); ?} ? ?int main() { ?? ?match *head; ?? ?char x; ?? ?do{ ?? ?system("cls"); ?? ?system("color 72"); ?? ?menu(); ?? ?x=getch(); ?? ?switch(x) ?? ?{ ?? ? ?? ??? ?case '1': ?? ??? ??? ?head=creat(); ?? ??? ??? ?break; ?? ??? ?case '2': ?? ??? ??? ?head=Add(head); ?? ??? ??? ?break; ?? ??? ?case '3': ?? ??? ??? ?print(head); ?? ??? ??? ?break; ?? ??? ?case '4': ?? ??? ??? ?head=Del(head); ?? ??? ??? ?break; ?? ??? ?case '5': ?? ??? ??? ?head=Amend(head); ?? ??? ??? ?break; ?? ??? ?case '6': ?? ??? ??? ?End(); ?? ??? ??? ?break; ?? ??? ?default: ?? ??? ??? ?printf("Input error!Please input again:");?? ? ?? ?} ? ? }while(1);//永遠(yuǎn)為真? ? ?? ?? ?return 0; }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C++?vector的簡(jiǎn)單實(shí)現(xiàn)
這篇文章主要為大家詳細(xì)介紹了C++?vector的簡(jiǎn)單實(shí)現(xiàn),使用數(shù)據(jù)庫(kù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助2022-03-03Qt串口通信開(kāi)發(fā)之QSerialPort模塊Qt串口通信接收數(shù)據(jù)不完整的解決方法
這篇文章主要介紹了Qt串口通信開(kāi)發(fā)之QSerialPort模塊Qt串口通信接收數(shù)據(jù)不完整的解決方法,需要的朋友可以參考下2020-03-03c語(yǔ)言實(shí)現(xiàn)通訊錄管理系統(tǒng)詳細(xì)實(shí)例
這篇文章主要給大家介紹了關(guān)于c語(yǔ)言實(shí)現(xiàn)通訊錄管理系統(tǒng)的相關(guān)資料,通訊錄管理系統(tǒng)是一種常見(jiàn)的應(yīng)用程序,可以用來(lái)管理聯(lián)系人的信息,包括姓名、電話號(hào)碼、地址等,需要的朋友可以參考下2023-07-07C++ DLL動(dòng)態(tài)庫(kù)的創(chuàng)建與調(diào)用(類庫(kù),隱式調(diào)用)
本文主要介紹了C++ DLL動(dòng)態(tài)庫(kù)的創(chuàng)建與調(diào)用(類庫(kù),隱式調(diào)用),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05C語(yǔ)言開(kāi)發(fā)之歸并排序詳解及實(shí)例
這篇文章主要介紹了 C語(yǔ)言開(kāi)發(fā)之歸并排序詳解及實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-03-03C語(yǔ)言實(shí)現(xiàn)紙牌計(jì)算24點(diǎn)小游戲
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)紙牌計(jì)算24點(diǎn)小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-10-10簡(jiǎn)要對(duì)比C語(yǔ)言中三個(gè)用于退出進(jìn)程的函數(shù)
這篇文章主要介紹了C語(yǔ)言中三個(gè)用于退出進(jìn)程的函數(shù)的對(duì)比,分別為_(kāi)exit()函數(shù)和on_exit()函數(shù)以及atexit()函數(shù),需要的朋友可以參考下2015-08-08