zoukankan      html  css  js  c++  java
  • 打渔晒网

     1 //当天的前一年离1990年有几天,再加上当年的天数,余数 1 2 3则打鱼,否则晒网
     2 #include <iostream>
     3 #include <cstring>
     4 using namespace std;
     5 
     6 const int a[2][13] = {0,31,28,31,30,31,30,31,31,30,31,30,31,
     7 0,31,29,31,30,31,30,31,31,30,31,30,31} ;
     8 
     9 typedef struct Node
    10 {
    11      int year,month,day;
    12 }Node;
    13 
    14 int is_leap(int year)
    15 {
    16      if(year%4==0&&year%100!=0||year%400 == 0)//符合短路表达式规则
    17           return 1;
    18      return 0;
    19 } 
    20 
    21 int sum_days(Node today)
    22 {
    23      int sum = 0;
    24      int i,j,k;
    25      for(i = 1990; i<today.year; i++)//没加等号,当天的前一年离1990年有几天,再加上当年的天数 
    26      {
    27           int flag = is_leap(i);
    28           if(flag)
    29                sum += 366;
    30           else
    31                sum += 365;
    32      }
    33      int tag = is_leap(today.year);
    34      for(i=1; i<today.month; i++)
    35           sum += a[tag][i];
    36      sum += today.day;//加上当月的天数 ,即便输入1990 1 1日, 则sum值为1,所以余数为1 2 3时打鱼,不是 0 1 2 
    37      return sum;
    38 }
    39 
    40 int main()
    41 {
    42      int i,j,k;
    43      Node today;
    44      cout<<"Input date:"<<endl;
    45      while(cin>>today.year>>today.month>>today.day)
    46      {
    47           int sum = sum_days(today);
    48           int mod = sum%5;
    49           if(mod>0&&mod<4)
    50                cout<<"打鱼"<<endl;
    51           else
    52                cout<<"晒网"<<endl;
    53      }
    54      return 0;
    55 }
    56      
    57      
    58      
    59      
  • 相关阅读:
    php多态
    ssl certificate problem: self signed certificate in certificate chain
    test plugin
    open specific port on ubuntu
    junit vs testng
    jersey rest service
    toast master
    use curl to test java webservice
    update folder access
    elk
  • 原文地址:https://www.cnblogs.com/hxsyl/p/2819187.html
Copyright © 2011-2022 走看看