| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 945 人关注过本帖
标题:数学高手进来帮帮忙看看完善下这个码吧@_@!
只看楼主 加入收藏
gzliujie5
Rank: 1
来 自:贵州
等 级:新手上路
帖 子:22
专家分:5
注 册:2011-8-13
结帖率:66.67%
收藏
已结贴  问题点数:10 回复次数:18 
数学高手进来帮帮忙看看完善下这个码吧@_@!
#include "iostream.h"
int main()
{
    int a,b,c;
    char aper,count;
    cout<<"输入日期(如:2005-2-8):";
    cin>>a>>aper>>b>>count>>c;
    cout<<a<<aper<<b<<count<<c<<endl;
    switch ((a+3)/4-a/4&&(a/400+3)-a/400&&(a+399)/400-a/400)
    {
    case 0:
        if(b==1&&c&&c<=31) cout<<a<<"年"<<b<<"月"<<c<<"日是闰年"<<a<<"年的第"<<c<<"天!"<<endl;
        else
        {
            if(b==2&&c<=29) cout<<a<<"年"<<b<<"月"<<c<<"日是闰年"<<a<<"年的第"<<c+31<<"天!"<<endl;
            else
            {
                if(b==3&&c<=31) cout<<a<<"年"<<b<<"月"<<c<<"日是闰年"<<a<<"年的第"<<c+60<<"天!"<<endl;
                else
                {
                    if(b==4&&c<=30) cout<<a<<"年"<<b<<"月"<<c<<"日是闰年"<<a<<"年的第"<<c+91<<"天!"<<endl;
                    else
                    {
                        if(b==5&&c<=31) cout<<a<<"年"<<b<<"月"<<c<<"日是闰年"<<a<<"年的第"<<c+121<<"天!"<<endl;
                        else
                        {
                            if(b==6&&c<=30) cout<<a<<"年"<<b<<"月"<<c<<"日是闰年"<<a<<"年的第"<<c+152<<"天!"<<endl;
                            else
                            {
                                if(b==7&&c<=31) cout<<a<<"年"<<b<<"月"<<c<<"日是闰年"<<a<<"年的第"<<c+182<<"天!"<<endl;
                                else
                                {
                                    if(b==8&&c<=31) cout<<a<<"年"<<b<<"月"<<c<<"日是闰年"<<a<<"年的第"<<c+213<<"天!"<<endl;
                                    else
                                    {
                                        if(b==9&&c<=30) cout<<a<<"年"<<b<<"月"<<c<<"日是闰年"<<a<<"年的第"<<c+244<<"天!"<<endl;
                                        else
                                        {
                                            if(b==10&&c<=31) cout<<a<<"年"<<b<<"月"<<c<<"日是闰年"<<a<<"年的第"<<c+274<<"天!"<<endl;
                                            else
                                            {
                                                if(b==11&&c<=30) cout<<a<<"年"<<b<<"月"<<c<<"日是闰年"<<a<<"年的第"<<c+305<<"天!"<<endl;
                                                else
                                                {
                                                    if(b==12&&c<=31) cout<<a<<"年"<<b<<"月"<<c<<"日是闰年"<<a<<"年的第"<<c+335<<"天!"<<endl;
                                                    else cout<<"错误日期!"<<endl;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        break;
    case 1:
        if(b==1&&c<=31) cout<<a<<"年"<<b<<"月"<<c<<"日是平年"<<a<<"年的第"<<c<<"天!"<<endl;
        else
        {
            if(b==2&&c<=28) cout<<a<<"年"<<b<<"月"<<c<<"日是平年"<<a<<"年的第"<<c+31<<"天!"<<endl;
            else
            {
                if(b==3&&c<=31) cout<<a<<"年"<<b<<"月"<<c<<"日是平年"<<a<<"年的第"<<c+59<<"天!"<<endl;
                else
                {
                    if(b==4&&c<=30) cout<<a<<"年"<<b<<"月"<<c<<"日是平年"<<a<<"年的第"<<c+90<<"天!"<<endl;
                    else
                    {
                        if(b==5&&c<=31) cout<<a<<"年"<<b<<"月"<<c<<"日是平年"<<a<<"年的第"<<c+120<<"天!"<<endl;
                        else
                        {
                            if(b==6&&c<=30) cout<<a<<"年"<<b<<"月"<<c<<"日是平年"<<a<<"年的第"<<c+151<<"天!"<<endl;
                            else
                            {
                                if(b==7&&c<=31) cout<<a<<"年"<<b<<"月"<<c<<"日是平年"<<a<<"年的第"<<c+181<<"天!"<<endl;
                                else
                                {
                                    if(b==8&&c<=31) cout<<a<<"年"<<b<<"月"<<c<<"日是平年"<<a<<"年的第"<<c+212<<"天!"<<endl;
                                    else
                                    {
                                        if(b==9&&c<=30) cout<<a<<"年"<<b<<"月"<<c<<"日是平年"<<a<<"年的第"<<c+243<<"天!"<<endl;
                                        else
                                        {
                                            if(b==10&&c<=31) cout<<a<<"年"<<b<<"月"<<c<<"日是平年"<<a<<"年的第"<<c+273<<"天!"<<endl;
                                            else
                                            {
                                                if(b==11&&c<=30) cout<<a<<"年"<<b<<"月"<<c<<"日是平年"<<a<<"年的第"<<c+304<<"天!"<<endl;
                                                else
                                                {
                                                    if(b==12&&c<=31) cout<<a<<"年"<<b<<"月"<<c<<"日是平年"<<a<<"年的第"<<c+334<<"天!"<<endl;
                                                    else cout<<"错误日期!"<<endl;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        break;
    }
    return 0;
}
搜索更多相关主题的帖子: 400 include count 数学 
2011-08-13 12:16
gzliujie5
Rank: 1
来 自:贵州
等 级:新手上路
帖 子:22
专家分:5
注 册:2011-8-13
收藏
得分:0 
有兴趣的帮忙看下,这个码还有很多错误的运算,但是我数学不是很厉害,公式实在不知道杂用了,高手帮忙指点下。
能够帮忙简化和校正,感激不尽啊。
2011-08-13 12:18
baobaoisme
Rank: 7Rank: 7Rank: 7
来 自:AVATAR
等 级:黑侠
帖 子:260
专家分:506
注 册:2010-7-9
收藏
得分:0 
天。。。你这代码风格。。。太有爱了。。。
建议把每个月天数保存在一个数组里面,大小设置为12,比如 int days[12],里面初始化为非闰年的每月的天数,如果是闰年那么修改day[1]的天数为29即可,可以看着好很多。。。
2011-08-13 12:21
naruto01
Rank: 4
等 级:业余侠客
帖 子:103
专家分:280
注 册:2011-5-23
收藏
得分:0 
滚动滑轮 挺有动感
2011-08-13 13:36
loveshuang
Rank: 9Rank: 9Rank: 9
来 自:湖北武汉
等 级:蜘蛛侠
帖 子:270
专家分:1198
注 册:2010-11-14
收藏
得分:10 
    简化后的程序:
#include "iostream.h"
int main()
{
    int a,b,c;
    char aper,count;
    cout<<"输入日期(如:2005-2-8):";
    cin>>a>>aper>>b>>count>>c;
    cout<<a<<aper<<b<<count<<c<<endl;

    int key;
    if(a%400==0||a%4==0&&a%100!=0)
        key=1;
    else
        key=0;
    switch (key)
    {
    case 1:
        cout<<a<<"年是闰年"<<endl;
        break;
    case 0:
        cout<<a<<"年是平年"<<endl;
        break;
    }

    int sum=31+28+key+31+30+31+30+31+30+30+31+30+31+c;
    switch(b)
    {
    case 1:
        sum-=31;
    case 2:
        sum-=(key+28);
    case 3:
        sum-=31;
    case 4:
        sum-=30;
    case 5:
        sum-=31;
    case 6:
        sum-=30;
    case 7:
        sum-=31;
    case 8:
        sum-=30;
    case 9:
        sum-=30;
    case 10:
        sum-=31;
    case 11:
        sum-=30;
    case 12:
        sum-=31;
    }
    cout<<a<<aper<<b<<count<<c<<"是"<<a<<"年的第"<<sum<<"天"<<endl;
    return 0;
}
2011-08-13 14:54
New_Born
Rank: 1
来 自:河南郑州
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-8-13
收藏
得分:0 


楼猪还有耐心
2011-08-13 15:14
gzliujie5
Rank: 1
来 自:贵州
等 级:新手上路
帖 子:22
专家分:5
注 册:2011-8-13
收藏
得分:0 
回复 5楼 loveshuang
if(a%400==0||a%4==0&&a%100!=0)
这个高手,这个可以解释解释么~~~你的码没有备注,我看得不是很懂,刚学没几天呢~~~
2011-08-13 16:53
loveshuang
Rank: 9Rank: 9Rank: 9
来 自:湖北武汉
等 级:蜘蛛侠
帖 子:270
专家分:1198
注 册:2010-11-14
收藏
得分:0 
回复 7楼 gzliujie5
那个是闰年和平年的判断,能被400整除或能被4整除且不能被100整除的就是闰年,闰年和平年的区别不就是二月的不同嘛,就用key表示1或0,在28上加key表示二月的天数。
switch语句也相当于是个条件语句,没有break的时候找到相等的就一直向下执行完;
2011-08-13 17:38
gzliujie5
Rank: 1
来 自:贵州
等 级:新手上路
帖 子:22
专家分:5
注 册:2011-8-13
收藏
得分:0 
呵呵,看懂了,谢谢啊,谢谢了,%是整除,我以为是除了之后可以有小数,如10%3=3.33333...看来我误会了,呵呵。只知道10/3=3.呵呵
十分感谢!

再问个问题~~~  -=是什么意思?sum-=31;   解释下,这个代码我就全懂咯。
2011-08-13 18:47
gzliujie5
Rank: 1
来 自:贵州
等 级:新手上路
帖 子:22
专家分:5
注 册:2011-8-13
收藏
得分:0 
回复 8楼 loveshuang
呵呵,看懂了,谢谢啊,谢谢了,%是整除,我以为是除了之后可以有小数,如10%3=3.33333...看来我误会了,呵呵。只知道10/3=3.呵呵
十分感谢!

再问个问题~~~  -=是什么意思?sum-=31;   解释下,这个代码我就全懂咯。

再帮忙解释解释,呵呵,感激不尽啊,嘿嘿。
2011-08-13 18:49
快速回复:数学高手进来帮帮忙看看完善下这个码吧@_@!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.046415 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved