zoukankan      html  css  js  c++  java
  • usaco1.1.3 Friday the Thirteenth 题解

    【算法】模拟  【难度】☆☆☆☆☆


    很简单的模拟题,关键是读清楚题,注意如何判断闰年。
    View Code
     1 /*
    2 ID: wsc5001
    3 LANG: C
    4 TASK: friday
    5 */
    6 #include<stdio.h>
    7 int runnian(int y)
    8 {
    9 if (y%100==0)
    10 {
    11 if (y%400==0)
    12 return 1;
    13 else
    14 return 0;
    15 }
    16 if (y%4==0)
    17 return 1;
    18 }
    19 int xingqi(int yu)
    20 {
    21 switch (yu)
    22 {
    23 case 0:return 6;
    24 case 1:return 7;
    25 default:return yu-1;
    26 }
    27 }
    28 int main()
    29 {
    30 FILE *fin,*fout;
    31 fin=fopen("friday.in","r");
    32 fout=fopen("friday.out","w");
    33 int i,j,n,runyear,tongji[8]={0},dayone=1,t;
    34 fscanf(fin,"%d",&n);
    35 for(i=0;i<n;i++)
    36 {
    37 runyear=runnian(1900+i);
    38 for(j=1;j<=12;j++)
    39 {
    40 t=xingqi((dayone+13)%7);
    41 tongji[t]+=1;
    42 if(j==2)//二月
    43 {
    44 if (runyear==1)
    45 dayone=xingqi(dayone+29+1); //闰年
    46 else
    47 dayone=xingqi(dayone+28+1);
    48 }
    49 else if(j==4||j==6||j==9||j==11)//小月
    50 dayone=xingqi(dayone+30+1);
    51 else//大月
    52 dayone=xingqi(dayone+31+1);
    53 }
    54 }
    55 fprintf(fout,"%d %d %d %d %d %d %d\n",tongji[6],tongji[7],tongji[1],tongji[2],tongji[3],tongji[4],tongji[5]);
    56 //printf("%d %d %d %d %d %d %d\n",tongji[6],tongji[7],tongji[1],tongji[2],tongji[3],tongji[4],tongji[5]);
    57 fclose(fin);
    58 fclose(fout);
    59 //getchar();
    60 }
  • 相关阅读:
    python3 基础数据类型之列表及其操作方法
    python3 逻辑运算符
    python3 内置函数
    python3 装饰器
    python3 变量作用域
    python3 参数以及函数的传参
    python3 函数基础
    洛谷P3379倍增LCA
    洛谷P3375KMP字符串匹配
    洛谷P2613有理数取余
  • 原文地址:https://www.cnblogs.com/loveidea/p/2416919.html
Copyright © 2011-2022 走看看