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;
          }
          測試結果:

          另一個測試:

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

          主站蜘蛛池模板: 仪陇县| 郯城县| 长寿区| 白水县| 合肥市| 湖口县| 繁昌县| 徐闻县| 淮滨县| 泉州市| 吴桥县| 宣威市| 通城县| 香河县| 巫山县| 专栏| 株洲县| 隆化县| 北海市| 土默特右旗| 宜君县| 东乌珠穆沁旗| 固镇县| 麻江县| 清涧县| 石河子市| 乾安县| 长丰县| 德安县| 浠水县| 堆龙德庆县| 宿迁市| 高青县| 江山市| 长海县| 措勤县| 天等县| 盱眙县| 互助| 清镇市| 天台县|