C++:足球联赛积分系统

16 篇文章 1 订阅
#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
#include<stdlib.h>
using namespace std;
class Team
{
public:
    Team(char n[15],int s,int w,int d,int l,int g,int lo,int sc):sum(s),win(w),draw(d),lost(l),get(g),lose(lo),score(sc)
    {
        int i;
        for(i=0;i<15;i++)
            name[i]=n[i];
    };
    Team(){};
    int sum,win,draw,lost,get,lose,score;
    char name[15];
    Team operator +(Team &a)
    {
        sum=sum+1;
        get=get+a.get;
        lose=lose+a.lose;
        if(a.get>a.lose)win=win+1;
        else if(a.get==a.lose)draw=draw+1;
        else lost=lost+1;
        score=win*3+draw;
        return *this;
    };
    void Dispaly()
    {
        cout<<setw(15)<<name<<setw(10)<<sum<<setw(10)<<win<<setw(10)<<draw<<setw(10)<<lost<<setw(10)<<get<<setw(10)<<lose<<setw(10)<<score<<endl;
    };
};
void Change(Team &a,Team &b)
{
    Team c;
    c=a;
    a=b;
    b=c;
};
void main()
{
    cout<<endl<<endl<<endl;
    cout<<"□□□□□  □□□   □□□  □□□□□ □□□□    □   □□□   □□□   "<<endl;
    cout<<" □  □ □   □ □   □ □ □ □  □  □   □    □     □    "<<endl;
    cout<<" □ □  □   □ □   □   □    □  □   □□   □     □    "<<endl;
    cout<<" □□□  □   □ □   □   □    □□□   □ □   □     □    "<<endl;
    cout<<" □ □  □   □ □   □   □    □  □  □ □   □     □    "<<endl;
    cout<<" □    □   □ □   □   □    □  □  □□□□  □     □    "<<endl;
    cout<<" □    □   □ □   □   □    □  □  □  □  □   □ □   □"<<endl;
    cout<<"□□□    □□□   □□□   □□□  □□□□  □□  □□□□□□□□□□□□□□"<<endl;
    cout<<endl<<"目前比赛的排名为:"<<endl<<endl;;
    cout<<setw(5)<<"名次"<<setw(15)<<"队名"<<setw(10)<<"比赛场数"<<setw(10)<<"胜场"<<setw(10)<<"平局"<<setw(10)<<"败场"<<setw(10)<<"进球"<<setw(10)<<"输球"<<setw(10)<<"总分"<<endl;
    ifstream in("score.txt");                
    if(!in)
    {
        cout<<"Unable to open in";
        exit(1);           
    }    
    char name[15],a[3];
    int sum,win,draw,lost,get,lose,score;
    int i,j;
    Team team[10];
    for(i=0;i<10;i++)
    {   
        in.get(a,2,' ');
        in.getline(name,15);
        in.clear();
        in.get(a,4);sum=atoi(a);
        in.get(a,4);win=atoi(a);
        in.get(a,4);draw=atoi(a);
        in.get(a,4);lost=atoi(a);
        in.get(a,4);get=atoi(a);
        in.get(a,4);lose=atoi(a);
        in.get(a,4);score=atoi(a);
        Team t(name,sum,win,draw,lost,get,lose,score);
        team[i]=t;
    }
    in.close;
    for(i=0;i<9;i++)
        for(j=i+1;j<10;j++)
            if(team[i].score<team[j].score)
            Change(team[i],team[j]);
    for(i=0;i<10;i++)
    {
        cout<<setw(5)<<i+1;
        team[i].Dispaly();
    }
    while(1)
    {   cout<<endl<<"请输入新一轮的比赛结果:"<<endl<<endl;
        char name1[15],name2[15];
        int get1,get2;
        cin>>name1>>name2>>get1>>get2;
        Team team1(name1,0,0,0,0,get1,get2,0);
        Team team2(name2,0,0,0,0,get2,get1,0);
        int t1=0,t2=0;
        int longth1=strlen(name1),longth2=strlen(name2);
        for(i=0;i<10;i++)
        {
            if(team[i].name[13]==team1.name[longth1-1]&&team[i].name[12]==team1.name[longth1-2]&&team[i].name[11]==team1.name[longth1-3]) t1=i;
            if(team[i].name[13]==team2.name[longth2-1]&&team[i].name[12]==team2.name[longth2-2]&&team[i].name[11]==team2.name[longth2-3]) t2=i;
        }
        team[t1]=team[t1]+team1;
        team[t2]=team[t2]+team2;
        for(i=0;i<9;i++)
            for(j=i+1;j<10;j++)
                if(team[i].score<team[j].score)
                Change(team[i],team[j]);
        cout<<endl<<"目前比赛的排名为:"<<endl<<endl;;
        cout<<setw(5)<<"名次"<<setw(15)<<"队名"<<setw(10)<<"比赛场数"<<setw(10)<<"胜场"<<setw(10)<<"平局"<<setw(10)<<"败场"<<setw(10)<<"进球"<<setw(10)<<"输球"<<setw(10)<<"总分"<<endl;
        for(i=0;i<10;i++)
        {
            cout<<setw(5)<<i+1;
            team[i].Dispaly();
        }   
        ofstream out("score.txt");
        if(!out)
        {
            cout<<"Unable to open out";
         exit(1);            
        }
        for(i=0;i<10;i++)
        {
            out<<setw(15)<<team[i].name<<setw(10)<<team[i].sum<<setw(10)<<team[i].win<<setw(10)<<team[i].draw<<setw(10)<<team[i].lost<<setw(10)<<team[i].get<<setw(10)<<team[i].lose<<setw(10)<<team[i].score<<endl;
        }
        out.close;
    }
} 
  • 3
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值