zoukankan      html  css  js  c++  java
  • HDU 2133 What day is it

    http://acm.hdu.edu.cn/showproblem.php?pid=2133

    Problem Description
    Today is Saturday, 17th Nov,2007. Now, if i tell you a date, can you tell me what day it is ?
     
    Input
    There are multiply cases.
    One line is one case.
    There are three integers, year(0<year<10000), month(0<=month<13), day(0<=day<32).
     
    Output
    Output one line.
    if the date is illegal, you should output "illegal". Or, you should output what day it is.
     
    Sample Input
    2007 11 17
     
    Sample Output
    Saturday
     
    时间复杂度:$O(1)$
    代码:
    #include <bits/stdc++.h>
    using namespace std;
    
    int a[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int b[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    char s[8][10] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
    bool IsRunNian(int year) {
        if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
            return true;
        return false;
    }
    int main() {
        int year, month, day;
        while(~scanf("%d%d%d", &year, &month, &day)) {
            if(IsRunNian(year)) {
                if(day > a[month] || month == 0 || day == 0) {
                    printf("illegal
    ");
                    continue;
                }
            } else{
                if(day > b[month] || month == 0 || day == 0) {
                    printf("illegal
    ");
                    continue;
                }
            }
            int sum = 0;
            for(int i = 1; i < year; i ++) {
                if(IsRunNian(i))
                    sum += 366;
                else
                    sum += 365;
                sum %= 7;
            }
            for(int i = 0; i < month; i ++) {
                if(IsRunNian(year))
                    sum += a[i];
                else
                    sum += b[i];
                sum %= 7;
            }
    
            sum += day;
            sum %= 7;
            printf("%s
    ",s[sum]);
        }
        return 0;
    }
    

      

  • 相关阅读:
    Django Rest Framework 视图和路由
    DRF 权限 频率
    DRF 版本 认证
    Serializers 序列化组件
    学DRF之前
    RESTful
    windows下vmware配置nat网络
    python之路——网络编程
    图片上传
    数据库基本设计规范:
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/9636934.html
Copyright © 2011-2022 走看看