試題02: 試設計程式, 提供下列各副程式的功能.


*請參考:【原創:"王氏口訣"】心算 "某日是星期幾" !


*假設日期 ws_date 的格式為 yyyymmdd 的(long)長整數, 例如: 16000301 表示1600/03/01


*假設現行的公曆曆法格里曆(Gregorian calendar)自1582年10月15日起算, 考慮實用性,


  及方便性, 以 1600/03/01做為第0天(base on 1600/03/01). 


1.計算 "日期(ws_date)"距離 "1600/03/01" 有幾天(*ret_days)?   該日期為星期幾(*ret_week)?


/* 輸入 "日期", 求得 "天數" 及 "星期幾" */


void date2days(unsigned long ws_date,unsigned long *ret_days, int *ret_week);


2. 輸入 "距離1600/03/01" 的天數ws_days, 求出 "該日期########" .


unsigned long days2date(unsigned long ws_days);


3.輸入 "兩個日期", 求相差的 "天數".


unsigned long count_days(unsigned long ws_date_from, unsigned long ws_date_to);


4. 檢查 "該日期是否合理有效" (有效return 0;無效return -1).


int date_valid(unsigned long ws_date);


      提示:先將 "日期" 轉 "天數", 再轉成另一個 "日期", 比對 "兩個日期" 是否相等.


 


 


..........................................................................................................


試題02中的功能已足夠應付 "商業上的用途", 而


試題03比較像是 "冷僻" 的數學題.




試題03: 試設計程式, 能提供上列第1及第2項功能,


             但是為 "設計電路" 上的要求,


             程式中不能使用表格或陣列來存12個月的對照值,


             也不能使用 "if" 或 "比大小" 或 "goto" 或 "迴圈" 的statement;


             只能利用 "+-*/" 或 "%" 等五種運算 "一行一行執行下來".

       例如下列四行是符合本條件的:


             ws_mm = ws_mmdd / 100;
             ws_dd = ws_mmdd % 100;


             jj      =       yyyy / 4 + yyyy / 400 - yyyy / 100;
             ii      =       jj + (306 * mm - 302) / 10 + ws_dd - 1; /* ii,jj,mm,ws_dd 皆宣告為整數 */



..........................................................................................................



註:日本某著名遊樂器近年曾因日期計算錯誤導致當機或使用者的記錄遺失.

      民國年份已由 "2位數" 升至 "3位數" , 有些資料檔案須將年份擴增一位.

      近期有人收到台電 "電費破億" 的帳單,  乃因資料欄位在擴增一位之後,

      轉檔發生錯誤, 與日期計算無關.


       


 


 


 


 



 

tools241 發表在 痞客邦 留言(0) 人氣()

/* btree.c --- debug by Mike Wang --- */
/*
ISAM主程式約一千多行,
(Indexed Sequential Access Method)

tools241 發表在 痞客邦 留言(0) 人氣()

/* 試題:   C(49,6)  ==> 試 "以最少比較次數" 印出 "大樂透(49個號碼取6個號碼)" 的所有可能開出的號碼(不含特別號) */
/* 以下共23行, 請修改下列有問號處?...... */
void main(int argc, char **argv)
{
  long ll = 0L;
  int i, j, nn[6]={1,2,3,4,5,6},kk[6]={1,2,3,4,5,6}, mm[6]={ ?,?,?,?,?,?};//C(49,6)
  for(;;)
  {
        printf("<%d %d %d %d %d %d>\n",kk[0],kk[1],kk[2],kk[3],kk[4],kk[5]);
        for(j=5;j>=1;j--)
        {
          if(kk[j]>mm[j])
          {
            ?......;
            ?......;
            ?......;
          }
        }
        ?......;
        if(kk[0]==mm[0])
          break;
        ?......;
  }
  printf("<%ld>\n",ll);
}

tools241 發表在 痞客邦 留言(0) 人氣()

/*
 程式檔名 : dc.c         (仿unix命令dc, 後置式計算機)
 功能說明 : desk caculator
 initial coding by Mike Wang
 設 計 者 :  (筆名)王駿(Mike Wang)
 免費參考: This library is free software.

tools241 發表在 痞客邦 留言(0) 人氣()

expr.c (仿unix命令expr)
/*
  * Expression Abstract Syntax Tree Functions
  *
  * Copyright 2002 Ove Kaaven
  * Copyright 2006-2008 Robert Shearman
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 

tools241 發表在 痞客邦 留言(0) 人氣()

grep.c    (仿unix命令grep) 約1697行, 48K





* grep 原本主要是在 unix/linux 下被用來找出 含/不含 某字串的工具,
    而在DOS下也可找到相容的grep.exe
* 在Windows下使用grep.exe時, 請先進 "命令提示元" 環境下操作
* 例1: 找含字串 2010 的文字行 ==>
grep.exe 2010 input.txt > output.txt
* 例2: 找以  abc 開頭, 且末尾是 789 的文字行 ==>
grep.exe "^abc.*789$" input.txt > output.txt
  註: ^ 表示後面的字在一行的開頭
    . 表示任意字
    * 表示前面的字出現任意次
    $ 表示前面的字在一行的末尾
* 例3 :找不含 the 的文字行 ==>
grep.exe  -v  the  input.txt > output.txt

tools241 發表在 痞客邦 留言(0) 人氣()

1
Blog Stats
⚠️

成人內容提醒

本部落格內容僅限年滿十八歲者瀏覽。
若您未滿十八歲,請立即離開。

已滿十八歲者,亦請勿將內容提供給未成年人士。