三天打鱼两天晒网

/*
软件名称:三天打鱼两天晒网
作者:贾浩义
完成日期:20173月
*/
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    int year,month,day;
    int temp;
    int y;
    int m;
    int sum=0;
    ifstream fin;
    fin.open("in.txt",ios::in);
    if(!fin.is_open())
    {
        cout << "打开输入文件错误";
        exit (1);
    }
    else {}
    ofstream fout;
    fout.open("out.txt",ios::out | ios::trunc);
    if(!fout.is_open())
    {
        cout << "打开输出文件错误"<<endl; 
        exit (0);
    }
    else {}
    while (!fin.eof())
    {   
        sum=0;
        fin>>temp;
        day=temp%100;
        month=((temp-day)%10000)/100;
        year=temp/10000;
        if(year<2010)
            {
                cout<<year<<"年"<<month<<"月"<<day<<"日";
                fout<<year<<"年"<<month<<"月"<<day<<"日";  
                cout<<"年份错误,请重新输入"<<endl<<endl;
                fout<<"年份错误,请重新输入"<<endl<<endl;
                continue;
            }
            else
            {
            {   y=year-2010;
            m=month-1;
            while(y>0)
            {
                if( (y%4==0 && y%100!=0) || (y%400==0) )  
                {
                    sum+=366;
                }
                else if(y%400==0)

                {
                    sum+=366;
                }
                else
                { 
                    sum+=365;
                }
                y--;
            }
            //计算从输入的日期到201011日共有多少天
            if(month>12||month<1)
            {
                cout<<year<<"年"<<month<<"月"<<day<<"日";
                fout<<year<<"年"<<month<<"月"<<day<<"日";
                cout<<"月份错误,请重新输入"<<endl<<endl;
                fout<<"月份错误,请重新输入"<<endl<<endl;
                continue;
            }
            else
            {
                {
            while(m>0)  
            {  
                switch(m)  
                {  
                    case 1:  
                    case 3:  
                    case 5:  
                    case 7:  
                    case 8:  
                    case 10:  
                    case 12:sum+=31;break;  //大月有31case 4:  
                    case 6:  
                    case 9:  
                    case 11:sum+=30;break; //小月有30case 2:  
                    {  
                        if( (year%4==0 && year%100!=0) || (year%400==0) )  
                        {  
                            sum+=29;break;  //闰年2月有29天
                        }  
                        else  
                        {  
                            sum+=28;break;  //平年2月有28天
                        }  
                    }  
                }  
                m--;  
            }  
            }
            }
            if(day>31||day<1)
            {
                cout<<year<<"年"<<month<<"月"<<day<<"日";
                fout<<year<<"年"<<month<<"月"<<day<<"日";
                cout<<"日期错误,请重新输入"<<endl<<endl;
                fout<<"日期错误,请重新输入"<<endl<<endl;
                continue;
            }
            else
            {
                {
            sum+=day; 
            cout<<"从2010年1月1日到"<<year<<"年"<<month<<"月"<<day<<"日"<<"总共经过了"<<sum<<"天"<<endl;
            fout<<"从2010年1月1日到"<<year<<"年"<<month<<"月"<<day<<"日"<<"总共经过了"<<sum<<"天"<<endl;

            if( (sum%5==1) || (sum%5==2) || (sum%5==3) )           //每5天分为一组,判断打鱼还是晒网  
            {  
                cout<<"今天打鱼"<<endl<<endl; 
                fout<<"今天打鱼"<<endl<<endl;
            }  
            else  
            {  
                cout<<"今天晒网"<<endl<<endl;  
                fout<<"今天晒网"<<endl<<endl;
            } 
    }}}}}
    fin.close();
    fout.close();

/*  cout<<"请输入要查询的年、月、日:"<<endl;
    cin>>year>>month>>day;
    if(year<2010)
    {
        cout<<"输入年份错误,请重新输入"<<endl;
    }
    else
    {
    {   y=year-2010;
    m=month-1;
    while(y>0)
    {
        if( (y%4==0 && y%100!=0) || (y%400==0) )  
        {
            sum+=366;
        }
        else if(y%400==0)

        {
            sum+=366;
        }
        else
        { 
            sum+=365;
        }
        y--;
    }
    //计算从输入的日期到201011日共有多少天
    if(month>12||month<1)
    {
        cout<<"输入月份错误,请重新输入"<<endl;
        exit(0);
    }
    else
    {
        {
    while(m>0)  
    {  
        switch(m)  
        {  
            case 1:  
            case 3:  
            case 5:  
            case 7:  
            case 8:  
            case 10:  
            case 12:sum+=31;break;  //大月有31case 4:  
            case 6:  
            case 9:  
            case 11:sum+=30;break; //小月有30case 2:  
            {  
                if( (year%4==0 && year%100!=0) || (year%400==0) )  
                {  
                    sum+=29;break;  //闰年2月有29天
                }  
                else  
                {  
                    sum+=28;break;  //平年2月有28天
                }  
            }  
        }  
        m--;  
    }  
    }
    }
    if(day>31||day<1)
    {
        cout<<"输入日期错误,请重新输入"<<endl;
    }
    else
    {
        {
    sum+=day;  
    if( (sum%5==1) || (sum%5==2) || (sum%5==3) )           //每5天分为一组,判断打鱼还是晒网  
    {  
        cout<<"今天打鱼"<<endl;  
    }  
    else  
    {  
        cout<<"今天晒网"<<endl;  
    }  
    cout<<sum<<endl;
    return 0;  
        }
    }
}
    }*/
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值