• 星际炸弹——炸弹爆炸时间计算


    题目:1900年1月1日是星期一,假如在1995年5月30日埋下一颗定时985天的炸弹,问几月几日星期几爆炸?假如1991年3月4日埋下一颗定时9764天的炸弹,问几月几日星期几爆炸!

     1 #include<stdio.h>
     2 #include<string.h>
     3 int leap(int year)
     4 {
     5     if(year%4==0&&year%100!=0||year%400==0)
     6     //①普通年能被4整除且不能被100整除的为闰年。②世纪年能被400整除的是闰年。
     7         return 1;//是闰年返回1 
     8     return 0;//不是闰年返回0 
     9 }
    10 int date(int o_yea,int o_mon,int o_day,int n_yea,int n_mon,int n_day)
    11 {
    12     int day=0;
    13     int i;
    14     int a[]={0,31,28,31,30,31,30,31,31,30,31,30,31};//平年 
    15     int b[]={0,31,29,31,30,31,30,31,31,30,31,30,31};//闰年 
    16     for(i=o_yea;i<=n_yea-1;i++)//整年计算 
    17         if(leap(i)==0)
    18             day+=365;
    19         else
    20             day+=366;
    21     for(i=1;i<=n_mon-1;i++)//新整月计算 求和 
    22         if(leap(n_yea)==0)
    23             day+=a[i];
    24         else
    25             day+=b[i];
    26     for(i=1;i<=o_mon-1;i++)//旧整月计算 求差 
    27         if(leap(o_yea)==0)
    28             day-=a[i];
    29         else
    30             day-=b[i];
    31     day+=n_day;//新零头天数 求和 
    32     day-=o_day;//旧零头天数 求差 
    33     return day;
    34 }
    35 void week(int y,int m,int d)
    36 {
    37     char weeks[7][7]={"星期一","星期二","星期三","星期四","星期五","星期六","星期天"};
    38     printf("%s
    ",weeks[date(1900,1,1,y,m,d)%7]);
    39 }
    40 main()
    41 {
    42     int o_yea,o_mon,o_day,n_yea,n_mon,n_day;
    43     int a[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    44     int b[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
    45     int i,j,k,days;
    46 Begain:
    47     printf("请输入埋放炸弹时间(yyyy mm dd):
    ");
    48     scanf("%d %d %d",&o_yea,&o_mon,&o_day);
    49     printf("请输入多少天后爆炸:
    ");
    50     scanf("%d",&days);
    51     for(i=1900;i<=2100;i++)
    52         for(j=1;j<=12;j++)
    53             for(k=1;k<=(leap(i)?b[j]:a[j]);k++)
    54                 if(days==date(o_yea,o_mon,o_day,i,j,k))
    55                 {
    56                     n_yea=i;
    57                     n_mon=j;
    58                     n_day=k;
    59                     goto Display;    
    60                 }
    61 Display:
    62     printf("%d年%d月%d日",n_yea,n_mon,n_day);
    63     week(n_yea,n_mon,n_day);
    64     goto Begain;
    65 }

  • 相关阅读:
    在 IdentityServer4 中创建客户端
    IdentityServer4 快速上手
    GraphQL Part IV: 浏览器内的 IDE
    GraphQL Part VII: 实现数据变更
    GraphQL Part VIII: 使用一对多查询
    GraphQL Part VI: 使用 Postgres 和 EF Core 持久化数据
    GraphQL Part V: 字段,参数和变量
    GraphQL Part III: 依赖注入
    GraphQL Part II: 中间件
    GraphQL Part I: hello, world.
  • 原文地址:https://www.cnblogs.com/wangyishan/p/7899115.html
Copyright © 2020-2023  润新知