| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 579 人关注过本帖
标题:输入日期,求星期,帮我查一下哪里错了,求助···
取消只看楼主 加入收藏
zhy7723998
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-12-29
结帖率:0
收藏
已结贴  问题点数:20 回复次数:0 
输入日期,求星期,帮我查一下哪里错了,求助···
题目描述
A year and the day of week of the first day in this year will be given to you, you are asked to calculate the day of week of any given date for this year.
输入
The input may contain several test cases.
The first line of each test case is a year (a 4-digit positive integer) and the day of week of the first day in this year (Sun, Mon, Tue, Wed, Thu, Fri, or Sat).
The second line is the given date of this year (in format of integer/integer, denoting Month/Day). You need to calculate the day of week of this date.
Input is terminated by EOF.
输出
For each test case, output the day of week of the given date in this year (i.e. Sun, Mon, Tue, Wed, Thu, Fri, or Sat)
样例输入
2009 Thu
12/25
1996 Mon
12/25
1984 Sun
2/2
样例输出
Fri
Wed
Thu

#include <iostream>
#include <string>
using namespace std;

int main()
{
    int y;
    string w;
    while(cin >> y >> w)
    {
        int m,d,n,W;
        if(w=="Sun")  W=0;
        else if(w=="Mom")  W=1;
        else if(w=="Tue")  W=2;
        else if(w=="Wed")  W=3;
        else if(w=="Thu")  W=4;
        else if(w=="Fri")  W=5;
        else if(w=="Sat")  W=6;
        scanf("%d/%d",&m,&d);
        if(m==1)  n=d%7;
        else if (m==2)  n=(d+31)%7;
        else
        {
            if ((y%4==0&&y%100!=0)||y%400==0)
            {
                if(m==3)  n=(d+31+29)%7;
                if(m==4)  n=(d+31+29+31)%7;
                if(m==5)  n=(d+31+29+31+30)%7;
                if(m==6)  n=(d+31+29+31+30+31)%7;
                if(m==7)  n=(d+31+29+31+30+31+30)%7;
                if(m==8)  n=(d+31+29+31+30+31+30+31)%7;
                if(m==9)  n=(d+31+29+31+30+31+30+31+31)%7;
                if(m==10)  n=(d+31+29+31+30+31+30+31+31+30)%7;
                if(m==11)  n=(d+31+29+31+30+31+30+31+31+30+31)%7;
                if(m==12)  n=(d+31+29+31+30+31+30+31+31+30+31+30)%7;
            }
            else
            {
                if(m==3)  n=(d+31+28)%7;
                if(m==4)  n=(d+31+28+31)%7;
                if(m==5)  n=(d+31+28+31+30)%7;
                if(m==6)  n=(d+31+28+31+30+31)%7;
                if(m==7)  n=(d+31+28+31+30+31+30)%7;
                if(m==8)  n=(d+31+28+31+30+31+30+31)%7;
                if(m==9)  n=(d+31+28+31+30+31+30+31+31)%7;
                if(m==10)  n=(d+31+28+31+30+31+30+31+31+30)%7;
                if(m==11)  n=(d+31+28+31+30+31+30+31+31+30+31)%7;
                if(m==12)  n=(d+31+28+31+30+31+30+31+31+30+31+30)%7;
            }
        }
        W=W+n;
        if(W>7)  W=W%7;
        else if(W==0)  cout << "Sun\n";
        else if(W==1)  cout << "Mom\n";
        else if(W==2)  cout << "Tue\n";
        else if(W==3)  cout << "Wed\n";
        else if(W==4)  cout << "Thu\n";
        else if(W==5)  cout << "Fri\n";
        else if(W==6)  cout << "Sat\n";
    }
    return 0;
}
搜索更多相关主题的帖子: positive contain several second 
2015-04-17 14:17
快速回复:输入日期,求星期,帮我查一下哪里错了,求助···
数据加载中...
 
   



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

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