zoukankan      html  css  js  c++  java
  • AcWing每日一题--十三号星期五

    https://www.acwing.com/problem/content/1343/

    按天枚举

     1 #include<iostream>
     2 using namespace std;
     3 int months[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
     4 int weekend[7];
     5 int get(int y,int m){
     6     if(m!=2) return months[m];
     7     else{
     8         if(y%100!=0&&y%4==0||y%400==0){
     9             return 29;
    10         }
    11         return 28;
    12     }
    13 }
    14 int main(void){
    15     int n;
    16     cin>>n;
    17     int days=0;
    18     int year=1900,month=1,day=1;
    19     while(year<1900+n){
    20         if(day==13){
    21             weekend[days%7]++;
    22         }
    23         days++;
    24         day++;
    25         if(day>get(year,month)) day=1,month++;
    26         if(month>12) month=1,year++;
    27     }
    28     for(int i=5,j=0;j<7;i=(i+1)%7,j++){
    29         cout<<weekend[i]<<" ";
    30     }
    31     return 0;
    32 }

    按月枚举

     1 #include<iostream>
     2 using namespace std;
     3 int months[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
     4 int weekend[7];
     5 int main(void){
     6     int n;
     7     cin>>n;
     8     int days=0;
     9     for(int year=1900;year<1900+n;year++){
    10         for(int month=1;month<=12;month++){
    11             weekend[(days+12)%7]++;
    12             days+=months[month];
    13             if(month==2){
    14                 if(year%100!=0&&year%4==0||year%400==0){
    15                     days++;
    16                 }
    17             }
    18         }
    19     }
    20     for(int i=5,j=0;j<7;i=(i+1)%7,j++){
    21         cout<<weekend[i]<<" ";
    22     }
    23     return 0;
    24 }
  • 相关阅读:
    异常处理、网络编程
    内置函数、反射、__str__、__del__、元类
    tomcat 拒绝服务
    html标签
    google 与服务器搭建
    liunx centox ssh 配置
    java 泛型
    Windows Mysql安装
    java 空对象
    java 动态代理(类型信息)
  • 原文地址:https://www.cnblogs.com/greenofyu/p/14308098.html
Copyright © 2011-2022 走看看