iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > 其他教程 >c语言实现足球比赛积分统计系统
  • 614
分享到

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

2024-04-02 19:04:59 614人浏览 八月长安
摘要

本文实例为大家分享了C语言实现足球比赛积分统计系统的具体代码,供大家参考,具体内容如下    //为简单化,这里没有加上文件的操作  #include <stdio.h&

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

 
 //为简单化,这里没有加上文件的操作 
#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;
}

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

--结束END--

本文标题: c语言实现足球比赛积分统计系统

本文链接: https://www.lsjlt.com/news/150119.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • c语言怎么计算字符串长度
    在C语言中,可以使用内置的strlen()函数来计算字符串的长度。该函数位于string.h头文件中。以下是一个示例代码: #inc...
    99+
    2024-05-14
    c语言
  • c语言怎么判断三个数的大小
    可以通过比较三个数之间的大小关系来判断它们的大小。以下是一个示例代码: #include <stdio.h> int ...
    99+
    2024-05-14
    c语言
  • c++排序函数sort怎么使用
    在C++中,使用sort函数对容器中的元素进行排序,可以按照默认的升序排列,也可以自定义排序规则。 下面是一个简单的例子,对一个ve...
    99+
    2024-05-14
    c++
  • c++中string的compare函数怎么使用
    在C++中,可以使用string的compare函数来比较两个string对象的大小。该函数的原型如下: int compare(c...
    99+
    2024-05-14
    c++
  • c++中string的compare函数有什么用
    c++中string的compare函数用于比较两个字符串的大小关系。该函数返回一个整数值,表示两个字符串的比较结果。 具体来说,如...
    99+
    2024-05-14
    c++
  • c++中print函数的功能有哪些
    在C++中,通常使用std::cout来进行输出操作,而不是使用print函数。std::cout是C++标准库中的一个输出流对象,...
    99+
    2024-05-14
    c++
  • c语言数据结构怎么使用
    在C语言中,数据结构可以通过定义结构体来实现。以下是一些常见的数据结构的使用方法示例: 链表: #include <std...
    99+
    2024-05-14
    c语言
  • c++中print函数的用法是什么
    在C++中没有内置的print函数,但可以使用cout来输出内容到控制台。cout是C++标准库中的一个输出流对象,可以使用<...
    99+
    2024-05-14
    c++
  • c++中concept的用法是什么
    在C++20中,Concept是一种新的语言特性,用于定义类型要求和约束。Concept可以被用来约束函数模板、类模板和普通函数的参...
    99+
    2024-05-14
    c++
  • c++中concept的作用是什么
    在C++中,concept的作用是定义一种通用的约束,用于限制模板参数的类型范围。通过使用concept,可以在编译时对模板参数进行...
    99+
    2024-05-14
    c++
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作