zoukankan      html  css  js  c++  java
  • 日期相差的天数计算201307311924.txt

    输入
    1978 10 1 1978 10 1
    1978 10 1 1978 10 2              
    1978 10 2 1978 10 1
    2001 1 1 2000 1 1
    2000 1 1 2002 1 1

    输出
    0
    1
    1
    366
    731

    #include "stdio.h"
    int main()
    {
     int b[2]={365,366};
       int a[2][13]={0,31,28,31,30,31,30,31,31,30,31,30,31,
                     0,31,29,31,30,31,30,31,31,30,31,30,31};
       int year1,month1,day1,year2,month2,day2;
       int s1,s2,i,s,t,j;
       scanf("%d%d%d%d%d%d",&year1,&month1,&day1,&year2,&month2,&day2);
       if(year1==year2)//同年份的情况
       {
        if(month1>month2)
        {t=month1;month1=month2;month2=t;}
        {t=day1;day1=day2;day2=t;}
        if(month1==month2&&day1>day2)
        {t=day1;day1=day2;day2=t;}
        s1=s2=0;
        j=(year1%400==0||(year1%4==0&&year1%100!=0));
         for(i=0;i<month1;i++)
         {
          s1=s1+a[j][i];
         }
         s1=s1+day1;
         for(i=0;i<month2;i++)
         {
          s2=s2+a[j][i];
         }
         s2=s2+day2;
         if(s1>s2)
         {t=s1;s1=s2;s2=t;}
         s=s2-s1;
       //printf("%d ",s);
       }
        if(year1>year2)//不同年份的情况
       {
       {t=year1;year1=year2;year2=t;}
       {t=month1;month1=month2;month2=t;}
       {t=day1;day1=day2;day2=t;}
       }
         if(year1<year2)
        {
         s=s1=s2=0;
         j=(year1%400==0||(year1%4==0&&year1%100!=0));
         for(i=0;i<month1;i++)
         {s1=s1+a[j][i];}
         s1=s1+day1;
         s1=b[j]-s1;
         j=(year2%400==0||(year2%4==0&&year2%100!=0));
         for(i=0;i<month2;i++)
         {s2=s2+a[j][i];}
         s2=s2+day2;
         year1+=1;
         j=(year1%400==0||(year1%4==0&&year1%100!=0));
         for(;year1<year2;)
         {
             s=s+b[j];
             year1+=1;
          j=(year1%400==0||(year1%4==0&&year1%100!=0));
         }
         s=s+s1+s2;
        }
         printf("%d ",s);
         return 0;

         

  • 相关阅读:
    js学习
    console用法
    Oracle 数据库加密
    Oracle 内存结构
    Oracle 锁
    Oracle 索引
    怎么理解“平均负载”
    Oracle分区表
    Oracle 数据库表(常见的表)
    PostgreSQL 监控磁盘使用
  • 原文地址:https://www.cnblogs.com/xiaziteng/p/5358139.html
Copyright © 2011-2022 走看看