hihocoder 2.29

题目链接:http://hihocoder.com/contest/msbop2015qual/problem/1

#include "stdafx.h"
#include <iostream>
#include <string>
#include <map>
using namespace std;
bool Judge_year(int year)
{
    if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
        return true;
    return false;
}
int main()
{
    int Num;
    cin >> Num;
    int d1, d2, y1, y2;
    string s1, s2;//存放月份
    map<string, int>reflect;
    //将字符串映射成数字,比较好处理
    reflect["January"] = 1;
    reflect["February"] = 2;
    reflect["March"] = 3;
    reflect["April"] = 4;
    reflect["May"] = 5;
    reflect["June"] = 6;
    reflect["July"] = 7;
    reflect["August"] = 8;
    reflect["September"] = 9;
    reflect["October"] = 10;
    reflect["November"] = 11;
    reflect["December"] = 12;

    for (int i = 0; i<Num; i++)//有不同的输入,所以有循环
    {
        //逗号的位置,严格按输入输出顺序
        char temp;
        int count = 0;
        cin >> s1 >> d1 >> temp >> y1;//January 12, 2012
        cin >> s2 >> d2 >> temp >> y2;
        int m1, m2;
        m1 = reflect[s1];
        m2 = reflect[s2];
        //先考虑同一年的情况
        if (y1 == y2)
        {
            if (Judge_year(y1))
            {
                if (m1 < 2 && m2>2)
                    count = 1;
                //如果第二个2.29则一定是cout=1
                //因为假定输入正确
                if (m1 < 2 && m2 == 2 && d2 == 29)
                    count = 1;
                if (m1 == 2 && m2>2)
                    count = 1;
                if (m1 == 2 && m2 == 2 && d2 == 29)
                    count = 1;
            }
        }
        else
            {
                //y1!=y2时
                if (Judge_year(y1))
                {
                    if (m1 <= 2)//只要如此一定有一个
                        count++;
                }
                if (Judge_year(y2))
                {
                    if (m2 > 2 || (m2 == 2 && d2 == 29))
                        count++;
                }

                    for (int j = y1 + 1; j <= y2 - 1;)
                    {
                        if (Judge_year(j))
                        {
                            count++;
                            j += 4;
                        }
                        else j++;
                    }
                }

        cout << "case #" << i+1 << ":" << count << endl;
        }

    }

你可能感兴趣的:(hihoCoder)