#include <iostream>
#include <string>
#include <cmath>
#include <fstream>
using namespace std;
int t;
fstream file;
class student
{public:
char event[40];
int num;
int a[5];
int p;
int sum;
int t;
char name[40];
char sex[40];
char school[40];
};student stu[4];
class sport
{public:
  char name[40];
  int month,day,hour,minute;
};sport spo[3];
void a()                                                   //输入比赛时间
{
    cout<<"请输入比赛的名称,月,日,时,分"<<endl;
    file.open("score.txt",ios::out);
    for(int i=0;i<3;i++)
    {
        cin>>spo[i].name>>spo[i].month>>spo[i].day>>spo[i].hour>>spo[i].minute;
    }
    for(i=0;i<3;i++)
    {
        file<<spo[i].name<<spo[i].month<<spo[i].day<<spo[i].hour<<spo[i].minute<<endl;
    }
    cout<<"输入结束"<<endl;
}
void b()                                     //查询运动员信息
{
    int b;
    
    
    cout<<"请输入运动员编号"<<endl;
    cin>>b;
    ifstream in("score.txt");

    for(int i=0;i<4;i++)
    {if(b==stu[i].num)


    cout<<stu[i].num<<"  "<<stu[i].name<<"  "<<stu[i].school<<"  "<<stu[i].sex<<"  "<<stu[i].event<<"  "<<stu[i].a[0]<<"  "<<stu[i].a[1]<<"  "<<stu[i].a[2]<<"  "<<stu[i].a[3]<<"  "<<stu[i].a[4]<<"  "<<stu[i].sum<<"  "<<stu[i].p<<endl;}
}
void c()                            //查询比赛时间
{
    cout<<"请输入您要查询的项目:";
    ifstream in("time.txt");
    char q[40];
    cin>>q;
    for(int i=0;i<3;i++)
    {if(strcmp(q,spo[i].name)==0)
    {cout<<"输出比赛时间:"<<endl;
    cout<<spo[i].month<<"月"<<spo[i].day<<"日"<<spo[i].hour<<"时"<<spo[i].minute<<"分"<<endl;}
    }

}
void d()   
{                                //修改比赛时间
    char ch1[40];
    char c,month,day,hour,minute;
    cout<<"请输入您要修改的项目:";
    cin>>ch1;
    for(int i=0;i<3;i++)
    {if(strcmp(spo[i].name,ch1)==0)
    {cout<<"1.修改月"<<"        "<<"2.修改日"<<endl;
     cout<<"3.修改时"<<"        "<<"4.修改分"<<endl;
    }
}
cin>>c;
switch(c)
{
case'1':
    {cout<<"请输入要修改的月:";
    cin>>month;
    spo[i].month=month;
    break;
    }
case'2':
    {cout<<"请输入要修改的日:";
    cin>>day;
    spo[i].day=day;
    break;
    }
case'3':
    {cout<<"请输入要修改的时:";
    cin>>hour;
    spo[i].hour=hour;
    break;
    }
case'4':
    {cout<<"请输入要修改的分:";
    cin>>minute;
    spo[i].minute=minute;
    break;
    }
default:
    cout<<"输入错误"<<endl;
}
cout<<"修改后的时间"<<endl;
for(i=0;i<3;i++)
{
    cout<<spo[i].month<<spo[i].day<<spo[i].hour<<spo[i].minute<<endl;
}
}
void e()                                  //输入运动员信息
{
int num;
char name[40];
char school[40];
char sex[40];
char event[40];
int m=0;
int p;
int sum;
char w;
int i,t,j;
file.open("student.txt",ios::out);
cout<<"请输入运动员编号、姓名、学校、性别、比赛项目及5个评分"<<endl;
do{
    cout<<"请输入:"<<endl;
    cin>>stu[m].num;
    cin>>stu[m].name;
    cin>>stu[m].school;
    cin>>stu[m].sex;
    cin>>stu[m].event;
    cin>>stu[m].a[0]>>stu[m].a[1]>>stu[m].a[2]>>stu[m].a[3]>>stu[m].a[4];
    sum=stu[m].a[0]+stu[m].a[1]+stu[m].a[2]+stu[m].a[3]+stu[m].a[4];
for(j=0;j<5;j++)
{for(i=0;i<5-j;i++)
{if(stu[m].a[i]>stu[m].a[i+1])
{t=stu[m].a[i];stu[m].a[i]=stu[m].a[i+1];stu[m].a[i+1]=t;}
p=(stu[m].a[1]+stu[m].a[2]+stu[m].a[3])/3;}
}
    
   
file<<num<<'\t'<<name<<'\t'<<school<<'\t'<<sex<<'\t'<<event<<'t'<<sum<<'\t'<<p<<endl;
m++;
cout<<"是否继续输入(a/b)"<<endl;
cin>>w;
if(w=='b')
break;
}
while(w=='a');
}
void f()                              //修改运动员信息
{
    char c;
    int num;
    char name[40];
    char sex[40];
    int i;
    int sum;
    cout<<"原始数据:"<<endl;
    ifstream in("score.txt");
    for(i=0;i<4;i++)
        cin>>stu[i].num>>stu[i].name>>stu[i].sex>>stu[i].t;
    for(i=0;i<4;i++)
        cout<<stu[i].num<<'\t'<<stu[i].name<<'\t'<<stu[i].school<<'\t'<<stu[i].sex<<'\t'<<stu[i].sum<<endl;
    char chl[40];
    cout<<"请输入您要修改的运动员姓名:";
    cin>>chl;
for(i=1;i<4;i++)
{
    if(strcmp(stu[i].name,chl)==0)
    {
        cout<<"1.修改编号"<<"         "<<"2.修改姓名"<<endl<<"3.修改性别"<<endl;
        cin>>c;
switch(c)
{
case'1':
    {
        cout<<"请输入您要修改的运动员编号:";
        cin>>num;
        stu[i].num=num;
        break;
    }
case'2':
    {
        cout<<"请输入您要修改的运动员姓名:";
        cin>>name;
        strcpy(stu[i].name,name);
        break;
    }
case'3':
    {
        cout<<"请输入您要修改的运动员性别:";
        cin>>sex;
        strcpy(stu[i].sex,sex);
        break;
    }
default:
    cout<<"您的输入有误!"<<endl;
}
    }
}
cout<<"修改后运动员的数据:";
for(i=0;i<4;i++)
{cout<<stu[i].num<<"  "<<stu[i].name<<"  "<<stu[i].sex<<"  "<<stu[i].t<<endl;}
}
void g()                       //删除运动员信息            
{
    int a;
    cout<<"请输入您要删除的学生学号:";
    cin>>a;
    for(int i=1;i<4;i++)
    {
        if((stu[i].num,a)==0)
        {
            for(int j=i;j<3;j++)
            stu[j]=stu[j+1];
        }
    }
cout<<"删除后运动员的数据:"<<endl;
for(i=0;i<3;i++)
cout<<stu[i].num<<'  '<<stu[i].name<<'  '<<stu[i].sex<<'  '<<stu[1].t<<endl;
}
int main()
{
    char c1;
    char ch2;
    cout<<endl<<endl<<"                               运动会管理系统"<<endl<<endl<<endl;
M:cout<<"          "<<"1.输入运动员信息"<<"                       "<<"2.输入比赛时间"<<endl<<endl<<"          "<<"3.查询运动员信息"<<"                       "<<"4.查询比赛时间"<<endl<<endl<<"          "<<"5.修改运动员信息"<<"                       "<<"6.修改比赛时间"<<endl<<endl<<"          "<<"7.删除运动员信息"<<"                       "<<"8.安全退出"<<endl;
  cout<<endl<<"          请根据提示输入!"<<endl;
cin>>c1;
switch (c1)
{
case'1':
    e();
    break;
case'2':
    a();
    break;
case'3':
    b();
    break;
case'4':
    c();
    break;
case'5':
    f();
    break;
case'6':
    d();
    break;
case'7':
    g();
    break;
case'8':
    exit(0);
default:
    cout<<"输入错误";
}
cout<<endl;
cout<<"继续操作请按x"<<endl;
cin>>ch2;
if(ch2=='x')
goto M;
return 0;
}