c语言实现足球比赛积分统计系统

 更新时间:2022年05月30日 10:18:52   作者:Sriven  
这篇文章主要为大家详细介绍了c语言实现足球比赛积分统计系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了c语言实现足球比赛积分统计系统的具体代码,供大家参考,具体内容如下

/* 足球比赛积分统计系统
   作者:施瑞文
   时间:2018.2
*/ 
 //为简单化,这里没有加上文件的操作 
#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];//[足球]队名
    int num[4];//num[0]为单支球队需比赛场数, num[1]为赢场数,num[2]为平场数,num[3]为负场数
    int goal;//进球数
    int lose;//失球数
    int integral;//积分
    int pure;//净胜球
    struct football *next; 
}match;
void menu();//声明菜单函数 
match *creat();//输入球队信息 
void print(match *head);//排序 
match *Add(match *head);//增加球队信息
match *Amend(match *head);//修改球队信息 
match *Del(match *head);//删除球队信息 
void End();//退出该软件 
 
int n=0;//记录节点长度 
match *p2;
 
void toxy(int x, int y)//将光标移动到X,Y坐标处
{
  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;
    
    /*录入足球队名,比赛场数,得、失 球数和进球积分*/ 
    
    /*输入第一个节点数据 */
 
    printf("Enter the total number of the football teams:");//参赛的球队数量 
    scanf("%d",&t);
    
    
    
    while(n!=t)
    {
        n++; 
        printf("the name of team %d :",n);//球队名 
        scanf("%s",p1->name);
    
        printf("team %d win round(s):",n);//该球队赢局场数 
        scanf("%d",&p1->num[1]);
    
        printf("team %d draw round(s):",n);//该球队平局场数 
        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)//增加球队 
{
    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);//球队名 
        scanf("%s",p->name);
    
        printf("team %d win round(s):",y);//该球队赢局场数 
        scanf("%d",&p->num[1]);
    
        printf("team %d draw round(s):",y);//该球队平局场数 
        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 :");//球队名 
            scanf("%s",p->name);
        
            printf("team win round(s):");//该球队赢局场数 
            scanf("%d",&p->num[1]);
        
            printf("team  draw round(s):");//该球队平局场数 
            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的前驱结点 
       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)//球队排序,冒泡法排序 ,关于链表的排序有点小复杂哦~ 
    {
        
        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指向第一个结点 
    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);//永远为真 
    
    return 0;
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • C++浅析内存分区模型概念与示例

    C++浅析内存分区模型概念与示例

    在了解内存分区之前,我们先来聊一聊为什么要进行内存分区。在进行了内存分区之后,在不同的区域存放的数据,会有不同的生命周期,从而会让程序员的编程变得更加灵活
    2022-09-09
  • C语言不使用strcpy函数如何实现字符串复制功能

    C语言不使用strcpy函数如何实现字符串复制功能

    这篇文章主要给大家介绍了关于C语言不使用strcpy函数如何实现字符串复制功能的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-02-02
  • 利用C语言实现将格式化数据和字符串相互转换

    利用C语言实现将格式化数据和字符串相互转换

    这篇文章主要为大家详细介绍了2个函数,分别是sprintf和sscanf,可以用来实现将格式化数据和字符串相互转换,感兴趣的小伙伴可以跟随小编一起学习一下
    2023-03-03
  • c++入门必学库函数sort的基本用法

    c++入门必学库函数sort的基本用法

    Sort函数包含在头文件为#include<algorithm>的c++标准库中,调用标准库里的排序方法可以不必知道其内部是如何实现的,只要出现我们想要的结果即可,下面这篇文章主要给大家介绍了关于c++入门必学库函数sort的基本用法,需要的朋友可以参考下
    2022-11-11
  • c语言strftime时间格式化示例

    c语言strftime时间格式化示例

    C/C++程序中需要程序显示当前时间,可以使用标准函数strftime,本文提供一个示例供大家参考
    2014-02-02
  • opencv3/C++实现光流点追踪

    opencv3/C++实现光流点追踪

    今天小编就为大家分享一篇opencv3/C++实现光流点追踪,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2019-12-12
  • 双缓冲解决VC++绘图时屏幕闪烁

    双缓冲解决VC++绘图时屏幕闪烁

    相信很多人在做图形界面开发时,常常会遇到屏幕闪烁的情况,当然我也不例外,下面我们就来详细探讨下这个问题的解决办法
    2015-08-08
  • Qt实现拖拽功能图文教程(支持拖放文件、拖放操作)

    Qt实现拖拽功能图文教程(支持拖放文件、拖放操作)

    这篇文章主要给大家介绍了关于Qt实现拖拽功能(支持拖放文件、拖放操作)的相关资料,Qt是一款多平台的C++应用程序开发框架,它的独特之处在于可以快速开发出拖放式的开发桌面程序,需要的朋友可以参考下
    2023-11-11
  • 深入学习C++中的函数概念

    深入学习C++中的函数概念

    这篇文章主要介绍了C++中的函数概念,是C++入门学习中的基础知识,需要的朋友可以参考下
    2015-09-09
  • C语言快速实现扫雷小游戏

    C语言快速实现扫雷小游戏

    这篇文章主要为大家详细介绍了C语言实现扫雷小游戏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2019-10-10

最新评论