zoukankan      html  css  js  c++  java
  • USACO Section 1.1-3 Friday the Thirteenth

    Friday the Thirteenth 黑色星期五

    13号又是一个星期五。13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数。

    给出N年的一个周期,要求计算1900年1月1日至1900+N-1年12月31日中十三号落在周一到周日的次数,N为正整数且不大于400.

    注意,开始今年是一千九百年,不是1990

    这里有一些你要知道的:

    1、1900年1月1日是星期一.

    2、4,6,11和9月有30天.其他月份除了2月都有31天.闰年2月有29天,平年2月有28天.

    3、年份可以被4整除的为闰年(1992=4*498 所以 1992年是闰年,但是1990年不是闰年).

    4、以上规则不适合于世纪年。可以被400整除的世纪年为闰年,否则为平年。所以,1700,1800,1900和2100年是平年,而2000年是闰年.

    请不要调用现成的函数

    请不要预先算好数据(就是叫不准打表)!

    PROGRAM NAME: friday

    INPUT FORMAT:

    (friday.in)

    一个正整数n.

    OUTPUT FORMAT:

    (friday.out)

    七个在一行且相分开的整数,它们代表13日是星期六,星期日,星期一...星期五的次数..

    SAMPLE INPUT:

    20

    SAMPLE OUTPUT:

    36 33 34 33 35 35 34

          依旧模拟...一天一天的模拟下去
          注意处理几号星期几就好了~~~
     1 /*
     2 ID: jvxie1
     3 PROG: friday
     4 LANG: C++ 
     5 */
     6 #include<cstdio>
     7 #include<cstring>
     8 #include<iostream>
     9 #include<algorithm>
    10 using namespace std;
    11 int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
    12 int day[10];
    13 int leap(int year)
    14 {
    15     if((year%4==0&&year%100!=0)||(year%400==0))
    16         return 1;
    17     return 0;
    18 }
    19 int work(int x,int year,int k)
    20 {
    21     int date=1;
    22     for(int i=0;i<12;i++)
    23         for(int j=1;j<=month[x][i];j++)
    24         {
    25             date++;
    26             date%=month[x][i];
    27             k++;k%=7;
    28             if(date==13)
    29                 day[k]++;
    30         }
    31     return k;
    32 }
    33 int main()
    34 {
    35     freopen("friday.in","r",stdin);
    36     freopen("friday.out","w",stdout);
    37     int n,k=1;
    38     scanf("%d",&n);
    39     for(int i=1900;i<=1900+n-1;i++)
    40         k=work(leap(i),i,k);
    41     printf("%d %d %d %d %d %d %d
    ",day[6],day[0],day[1],day[2],day[3],day[4],day[5]);
    42     return 0;
    43 }


  • 相关阅读:
    [CodeForces]Codeforces Round #429 (Div. 2) ABC(待补)
    About Me
    2018-06-14
    Codeforces Codeforces Round #484 (Div. 2) E. Billiard
    Codeforces Codeforces Round #484 (Div. 2) D. Shark
    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
    Codeforces Avito Code Challenge 2018 D. Bookshelves
    Codeforces Round #485 (Div. 2) D. Fair
    Codeforces Round #485 (Div. 2) F. AND Graph
  • 原文地址:https://www.cnblogs.com/JVxie/p/4936296.html
Copyright © 2011-2022 走看看