302班

          java突擊隊
          posts - 151, comments - 74, trackbacks - 0, articles - 14
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          #include <stdio.h>

          struct time
          {
            int hour;
            int minute;
            int second;
          };
          struct date
          {
             int year;
             int month;
             int day;
          };
          struct dateAndTime
          {
             struct date sdate;
             struct time stime;
          };
          struct dateAndTime clockKeeper(struct dateAndTime s)
          {
           struct dateAndTime nextTime;
              struct time timeUpdate(struct time now);
           struct date dateUpdate(struct date today);
           int i=s.stime.hour;
              nextTime.stime=timeUpdate(s.stime);
           nextTime.sdate=s.sdate;
           if(i!=0&&(s.stime.hour==0))
           {
             nextTime.sdate=dateUpdate(s.sdate);
           }
           
           return nextTime;  
          }
          //日期更新
          struct date dateUpdate(struct date today)

            int numberOfDays(struct date d);
            struct date tomorrow;
            if(today.day!=numberOfDays(today))
            { 
           tomorrow.day=today.day+1;
           tomorrow.month=today.month;
           tomorrow.year=today.year;
            }
            else if(today.month==12)
            {
               tomorrow.day=1;
            tomorrow.month=1;
            tomorrow.year=today.year+1;
            }
            else
            {
               tomorrow.day=1;
            tomorrow.month=today.month+1;
            tomorrow.year=today.year;
            }
            return tomorrow;
          }
            //查找一個月日期數的函數
            int numberOfDays(struct date d)
            {
               int days;
            int isLeapYear(struct date d);
            const int daysPerMonth[12]={31,28,31,30,31,30,31,31,30,31,30,31};
            if(isLeapYear(d)==1&&d.month==2)
            {
              days=29;
            }
            else
            {
              days=daysPerMonth[d.month-1];
            }
            return days;
            }
            //判定是不是瑞年
            int isLeapYear(struct date d)
            {
               int leapYearFlag;
            if((d.year%4==0&&d.year%100!=0)||d.year%400==0)
            {
                  leapYearFlag=1;
            }
            else
             leapYearFlag=0;
            return leapYearFlag;
            }
          //時間更新
            struct time timeUpdate(struct time now)
            {
              ++now.second;
           if(now.second==60)
           {
              now.second=0;
              ++now.minute;
              if(now.minute==60)
              {
             now.minute=0;
                ++now.hour;
             if(now.hour==24)
             {
               now.hour=0;
             }
              }  
           }
           return now;
            }
          int main(void)
          {
           struct dateAndTime s1={{2006,05,9},{23,59,59}};
           struct date today={2006,2,28};
           struct date tomorrow=dateUpdate(today);
           printf("%i%i%i\n",tomorrow.year,tomorrow.month,tomorrow.day);
           struct dateAndTime clockKeeper(struct dateAndTime s);
           
           struct dateAndTime upToNow=clockKeeper(s1);
           printf("The pre dateAndTime is %.4i/%.2i/%.2i  %.2i:%.2i:%.2i.\n",s1.sdate.year,s1.sdate.month,s1.sdate.day,s1.stime.hour,s1.stime.minute,s1.stime.second);
           printf("The pre dateAndTime is %.4i/%.2i/%.2i  %.2i:%.2i:%.2i.\n",upToNow.sdate.year,upToNow.sdate.month,upToNow.sdate.day,upToNow.stime.hour,upToNow.stime.minute,upToNow.stime.second);
              return 0;
          }
          測試結果:

          另一個測試:

          不過這里還存在一定的問題,就是日期不能更新,怪。還沒發現問題是什么

          主站蜘蛛池模板: 泰州市| 宁阳县| 新巴尔虎左旗| 聂荣县| 山东省| 那曲县| 辰溪县| 凤翔县| 郓城县| 镇宁| 定远县| 深州市| 上高县| 清涧县| 昔阳县| 婺源县| 双流县| 信宜市| 成武县| 广昌县| 临朐县| 四会市| 汉寿县| 漳州市| 井陉县| 白朗县| 三门峡市| 定南县| 兴海县| 嘉祥县| 太谷县| 台北县| 陈巴尔虎旗| 江达县| 时尚| 安徽省| 万安县| 望城县| 峨眉山市| 海晏县| 江华|