Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1559151
  • 博文数量: 327
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 3556
  • 用 户 组: 普通用户
  • 注册时间: 2005-04-05 21:28
个人简介

东黑布衣,流浪幽燕。 真诚善良,值得信赖。

文章分类

全部博文(327)

我的朋友

分类: BSD

2018-05-11 21:42:56


  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>

  4. int isWeekend(const char*date)
  5. {
  6.    int day_num[2][13] = { { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
  7.                           { 1, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } };
  8.    int i;

  9.    int tmp1 = 0;
  10.    int tmp2 = 0;
  11.    int year_diff = 0;

  12.    int total_day = 0;
  13.    char szYY[5];
  14.    char szMM[3];
  15.    char szDD[3];
  16.    int iYY;
  17.    int iMM;
  18.    int iDD;
  19.    strncpy(szYY, date, 4);
  20.    iYY = atoi(szYY);
  21.    strncpy(szMM, date + 4, 2);
  22.    iMM = atoi(szMM);
  23.    strncpy(szDD, date + 6, 2);
  24.    iDD = atoi(szDD);

  25.    year_diff = iYY - 2009;
  26.    if(year_diff == 0){
  27.       for(i = 1; i < iMM; i++){
  28.          tmp2 += day_num[0][i];
  29.       }
  30.       tmp2 += iDD;

  31.       tmp1 = 4;
  32.       total_day = tmp2 -tmp1;
  33.       if( total_day%7 != 0) /* Not Weekend */
  34.          return 0;
  35.       else /* Weekend */
  36.          return 1;

  37.    }else if(year_diff == 1){
  38.       for(i = 2; i <= 12; i++){
  39.          tmp1 += day_num[0][i];
  40.       }
  41.       tmp1 += (31-4);

  42.       for(i = 1; i < iMM; i++){
  43.          tmp2 += day_num[0][i];
  44.       }
  45.       tmp2 += iDD;

  46.       total_day = tmp2 + tmp1;
  47.       if( total_day%7 != 0) /* Not Weekend */
  48.          return 0;
  49.       else /* Weekend*/
  50.          return 1;

  51.    }else if(year_diff >= 2){
  52.       for(i = 2; i <= 12; i++){
  53.          tmp1 += day_num[0][i];
  54.       }
  55.       tmp1 += (31-4);

  56.       for(i = 1; i < iMM; i++){
  57.          tmp2 += day_num[0][i];
  58.       }
  59.       tmp2 += iDD;

  60.       total_day = tmp2 + tmp1;

  61.       for( i = 2010; i < iYY; i++){
  62.          if(((i%4 == 0) && (i%100 != 0)) || (i%400 == 0))
  63.             total_day += 366;
  64.          else
  65.             total_day += 365;
  66.       }

  67.       if(total_day%7 != 0) /* Not Weekend */
  68.          return 0;
  69.       else
  70.          return 1; /* Weekend */
  71.    }
  72.    return -1;
  73. }



  74. int main(int argc, char *argv[])
  75. {
  76.    if(isWeekend(argv[1]))
  77.       printf("%s is weekend\n", argv[1]);
  78.    else
  79.       printf("%s is not weekend\n", argv[1]);

  80.    return 0;
  81. }

阅读(1628) | 评论(0) | 转发(0) |
0

上一篇:红烧排骨的心得体会

下一篇:炖肘子

给主人留下些什么吧!~~