2014年6月6日 星期五

名人名言

If you can’t accept my worst part, you don’t deserve to possess the best part of mine.
If you leave when my dark time, you shouldn’t come back when my shinning days.

如果你不能接受最差的我,你就不配擁有最好的我,
如果你在我最低谷的時候離開,你就不要在我最輝煌的時候回來。

by Kobe Bryant
You can close your eyes to the things you do not want to see,
but you cannot close your heart to the things you do not want to feel. 

不想看到的事,你可以閉上眼睛;
但不想感覺的事,卻無法閉上心房。

by Johnny Depp
If you are passionate about something and cannot give it up.
You should work harder at it, and show others you exist.

如果對喜歡的事情沒有辦法放棄,那就要更努力地讓別人看到自己的存在。

逆光飛翔

2014年4月16日 星期三

走在鋼索上的人

每個人心中都有一份恐懼,
如果把恐懼融入到生活中,
漸漸的就會無視於它的存在,
就像走在鋼索上的人,
永遠沒有害怕的權力,
因為眼前所要面對的不是恐懼,
而是有沒有體力繼續走下去。

2014年4月10日 星期四

C語言 - 面試考題

1.給變數 int *p, *q, *r,使用malloc取得空間,計算1+…+10的值,用printf印出。
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    char *p, *q, *r;

    p = malloc(sizeof(unsigned int));
    q = malloc(sizeof(unsigned int));
    r = malloc(sizeof(unsigned int));

    *p = 1;
    *q = 1;
    *r = 0;

    for (*p = 0; *p < 10; (*p)++) {
        *r += *q;
        (*q)++;
    }

    printf("sum = %d\n", *r);

    free(p);
    free(q);
    free(r);

    return 0;
}
2.int a=3, b=5,寫一個swap(),使得 a=5, b=3。
#include <stdio.h>

void swap(int *a, int *b)
{
    *a = *a ^ *b;
    *b = *a ^ *b;
    *a = *a ^ *b;
}

int main(int argc, char *argv[])
{
    int a = 5, b = 10;

    printf("a = %d, b = %d\n", a, b);

    swap(&a, &b);

    printf("a = %d, b = %d\n", a, b);

    return 0;
}
3.x的內容為1,2,3,4,用loop分別印出。
typedef struct struct_list
{
    int x;
    struct struct_list *next;
}llst;
#include <stdio.h>
#include <stdlib.h>

typedef struct struct_list
{
    int x;
    struct struct_list *next;
} llst;

int main(int argc, char *argv[])
{
    llst *ptr, *head;
    int num, i, sum = 0;

    ptr = malloc(sizeof(struct struct_list));

    head = ptr;
    printf("please input 5 numbers => \n");

    for (i = 0; i < 5; i++) {
        scanf("%d", &num);
        ptr->x = num;

        ptr->next = malloc(sizeof(struct struct_list));
  
        if (i == 4)
            ptr->next = NULL;
        else
            ptr = ptr->next;
    }

    ptr = head;

    while (ptr) {
        printf("ptr->x = %d\n", ptr->x);
        sum += ptr->x;
        ptr = ptr->next;
    }
 
    printf("sum = %d\n", sum);
   
    return 0;
}
4. 請問f要如何宣告,可得到如下結果 </ br> Input 1</ br> Input 2</ br>
#include <stdio.h>

int aoo(int a)
{
    Printf(“Input%d\n”, a);
}
 
int boo(int b)
{
    Printf(“Input%d\n”, b);
}
 
Int main()
{
    f=aoo;
    f(1);
    f=boo;
    f(2);
}
#include <stdio.h>

int aoo(int a)
{
    printf("input %d\n", a);
    return 0;
}

int boo(int b)
{
    printf("input %d\n", b);
    return 0;
}

int main(int argc, char *argv[])
{
    int (*f)(int a);

    f = aoo;
    f(1);
 
    f = boo;
    f(2);

    return 0;
}
5.請寫一個遞回(recursive)範例
#include <stdio.h>

int recursive(int n)
{
    if (n == 1)
        return 1;
    return recursive(n - 1) + n;
}

int main(int argc, char *argv[])
{
    printf("sum = %d\n", recursive(5));
    printf("sum = %d\n", recursive(10));
 
    return 0;
}
6. int x=2, y=3, z; z=(x++)+y; 請問 x=? y=? z=?
#include <stdio.h>

int main(int argc, char *argv[])
{
    int x = 2, y = 3, z;

    z = (x++) + y;

    /* x = 3, y = 3, z = 5 */
    printf("x = %d, y = %d, z = %d\n", x, y, z);

    return 0;
}

2014年3月28日 星期五

C語言 - 累加總合 使用迴圈與遞迴

- 使用迴圈
結束條件: i > n

sum = 1
= 1 + 2
= 1 + 2 + 3
= 1 + 2 + 3 + ...
= 1 + 2 + 3 + ... + (n - 3)
= 1 + 2 + 3 + ... + (n - 3) + (n - 2)
= 1 + 2 + 3 + ... + (n - 3) + (n - 2) + (n - 1)
= 1 + 2 + 3 + ... + (n - 3) + (n - 2) + (n - 1) + n
#include <stdio.h>

int main(int argc, char *argv[])
{
 int i, n, sum = 0;

 printf("Enter a number: ");
 scanf("%d", &n);

 for (i = 1; i <= n; i++)
  sum +=i;

 printf("sum = %d\n", sum);
 return 0;
}
- 使用遞迴
結束條件: n == 1

calc(n) = calc(n - 1) + n
= calc(n - 2) + (n - 1) + n
= calc(n - 3) + (n - 2) + (n - 1) + n
= ...
= calc(3) + ... + (n - 3) + (n - 2) + (n - 1) + n
= calc(2) + 3 + ... + (n - 3) + (n - 2) + (n - 1) + n
= calc(1) + 2 + 3 + ... + (n - 3) + (n - 2) + (n - 1) + n
= 1 + 2 + 3 + ... + (n - 3) + (n - 2) + (n - 1) + n
#include <stdio.h>

int calc(int n)
{
 if (n == 1)
  return 1;

 return calc(n - 1) + n; 
}

int main(int argc, char *argv[])
{
 int n, sum;

 printf("Enter a number: ");
 scanf("%d", &n);
 sum = calc(n);

 printf("sum = %d\n", sum);
 return 0;
}

2014年3月20日 星期四

C語言 - 字串組合 使用遞迴

# Loop1
0 0 (abc)
        # Loop2    
        1 1 (abc)
                # Loop3
                2 2 (abc)
        1 2 (acb)
                2 2 (acb)
0 1 (bac)
        1 1 (bac)
                2 2 (bac)
        1 2 (bca)
                2 2 (bca)
0 2 (cba)
        1 1 (cba)
                2 2 (cba)
        1 2 (cab)
                2 2 (cab)
#include <stdio.h>
#include <math.h>

int perm(char *list, int i, int n);

int main(int argc, char *argv[])
{
    int i, n;
    char list[] = {'a', 'b', 'c'};

    i = 0;
    n = (sizeof(list) / sizeof(list[0])) - 1;

    perm(list, i, n);

    printf("\n");
    return 0;
}
#define SWAP(x, y, t) ((t) = (x), (x) = (y), (y) = (t))
int perm(char *list, int i, int n)
{
    int j, temp;
    if (i == n) {
        for (j = 0; j <= n; j++)
            printf("%c", list[j]);
            printf(" ");
    } else {
        for (j = i; j <= n; j++) {
            SWAP(list[i], list[j], temp);
            perm(list, i + 1, n);
            SWAP(list[i], list[j], temp);
        }
    }
}

C語言 - Binary Search 使用遞迴

1. 一組已排序n個整數
2. left = 0, right = n - 1
3. middle = (left + right) / 2
4.
searchnum > list[middle], left = middle + 1
searchnum = list[middle], return middle
searchnum < list[middle], right = middle - 1
5.
- 建立終止遞回呼叫的條件
- 建立遞回呼叫,使得每一次的呼叫更進一步接近解答
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int binsearch(int list[], int searchnum, int left, int right);

int main(int argc, char *argv[])
{
    int searchnum, left, right, pos;
    int list[] = {11, 22, 33, 44, 55, 66, 77, 88, 99};

    printf("Enter the numbfer you want to search: ");
    scanf("%d", &searchnum);

    left = 0;
    right = (sizeof(list)/sizeof(list[0])) - 1;

    pos = binsearch(list, searchnum, left, right);
    if (pos == -1)
        printf("not found\n");
    else
        printf("found pos: %d\n", pos);

    return 0;
}
#define COMPARE(x, y) (((x) < (y)) ? -1 : ((x) == (y)) ? 0 : 1)
int binsearch(int list[], int searchnum, int left, int right)
{
    int middle;
    if (left <= right) {
        middle = (left + right) / 2;
        switch(COMPARE(list[middle], searchnum)) {
        case -1:
            return binsearch(list, searchnum, middle + 1, right);
        case 0:
            return middle;
        case 1:
            return binsearch(list, searchnum, left, middle - 1);
        }
    }
    return -1;
}

C語言 - Binary Search 使用迴圈

1. 一組已排序n個整數
2. left = 0, right = n - 1
3. middle = (left + right) / 2
4.
searchnum > list[middle], left = middle + 1
searchnum = list[middle], return middle
searchnum < list[middle], right = middle - 1
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int binsearch(int list[], int searchnum, int left, int right);

int main(int argc, char *argv[])
{
    int searchnum, left, right, pos;
    int list[] = {11, 22, 33, 44, 55, 66, 77, 88, 99};

    printf("Enter the numbfer you want to search: ");
    scanf("%d", &searchnum);

    left = 0;
    right = (sizeof(list)/sizeof(list[0])) - 1;
    pos = binsearch(list, searchnum, left, right);
    if (pos == -1)
        printf("not found\n");
    else
        printf("found pos: %d\n", pos);

    return 0;
}
#define COMPARE(x, y) (((x) < (y)) ? -1 : ((x) == (y)) ? 0 : 1)
int binsearch(int list[], int searchnum, int left, int right)
{
    int middle;
    while (left <= right) {
        middle = (left + right) / 2;
        switch (COMPARE(list[middle], searchnum)) {
        case -1:
                left = middle + 1;
                break;
        case 0:
                return middle;
        case 1:
                right = middle - 1;
                break;
        }
    }
    return -1;
}

C語言 - 整數排序 Selection Sort

1. SWAP巨集
2. Selection Sort演算法
3. main函數的輸入與輸出
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define MAX_SIZE 100
void sort(int list[], int n);
int binsearch(int list[], int n, int left, int right);

int main(int argc, char *argv[])
{
 int i, n;
 int searchnum, left, right, pos;
 int list[MAX_SIZE];

 printf("Enter the number of numbers to generate: ");
 scanf("%d", &n);

 if ((n < 1) || (n > MAX_SIZE)) {
  fprintf(stderr, "Improper value of n\n");
  exit(1);
 }

 printf("hello\n");
 for (i = 0; i < n; i++) {
  list[i] = rand() % 1000;
  printf("%d ", list[i]);
 } 
 printf("\n");

 sort(list, n);

 for (i = 0; i < n; i++)
  printf("%d ", list[i]);
 printf("\n");

 printf("Enter the numbfer you want to search: ");
 scanf("%d", &searchnum);

 left = 0;
 right = n - 1;
 pos = binsearch(list, searchnum, left, right);
 if (pos == -1)
  printf("not found\n");
 else
  printf("found pos: %d\n", pos);

 return 0;
}
#define SWAP(x, y, t) ((t) = (x), (x) = (y), (y) = (t))
void sort(int list[], int n)
{
 int i, j, min, temp;
 for (i = 0; i < n-1; i++) {
  min = i;
  for (j = i+1; j < n; j++)
   if (list[min] > list[j])
    min = j;
  SWAP(list[i], list[min], temp);
 }
}

2014年3月6日 星期四

Blogger 圖片超出邊框的問題

1. 範本-> 自訂->

2. 進階-> 新增CSS
在"新增自定 CSS"方框中加入下面 CSS 設定
.post img {max-width: 98% !important}
3. 參考來源
http://sealmemory.blogspot.tw/2013/03/google-blogger.html

2014年2月25日 星期二

Blogger嵌入程式碼 - Syntax Highlighter 3.0.83

1. 從Syntax Highlighter的官方網站,下載最新的Syntax Highlighter 3.0.83
http://alexgorbatchev.com/SyntaxHighlighter/

2. 找到一個網路空間,將以下檔案上傳,可以上傳至"Google Site"
syntaxhighlighter_3.0.83\styles\shCore.css
syntaxhighlighter_3.0.83\styles\shThemeDefault.css
syntaxhighlighter_3.0.83\scripts\shCore.js
syntaxhighlighter_3.0.83\scripts\shBrushBash.js
syntaxhighlighter_3.0.83\scripts\shBrushCpp.js
syntaxhighlighter_3.0.83\scripts\shBrushDiff.js
syntaxhighlighter_3.0.83\scripts\shBrushPlain.js
syntaxhighlighter_3.0.83\scripts\shBrushXml.js
syntaxhighlighter_3.0.83\scripts\shBrushCss.js
3. 從Google Site找到這些檔案的超連結,將它填入下面的HTML語法中
範本-> 編輯HTML,將以下語法加到<head>之後。
<link href='https://sites.google.com/site/english0815/Home/syntaxhighlighter/shCore.css' rel='stylesheet' type='text/css'/>
<link href='https://sites.google.com/site/english0815/Home/syntaxhighlighter/shThemeDefault.css' rel='stylesheet' type='text/css'/>
<script src='https://sites.google.com/site/english0815/Home/syntaxhighlighter/shCore.js' type='text/javascript'/>
<script src='https://sites.google.com/site/english0815/Home/syntaxhighlighter/shBrushBash.js' type='text/javascript'/>
<script src='https://sites.google.com/site/english0815/Home/syntaxhighlighter/shBrushCpp.js' type='text/javascript'/>
<script src='https://sites.google.com/site/english0815/Home/syntaxhighlighter/shBrushDiff.js' type='text/javascript'/>
<script src='https://sites.google.com/site/english0815/Home/syntaxhighlighter/shBrushPlain.js' type='text/javascript'/>
<script src='https://sites.google.com/site/english0815/Home/syntaxhighlighter/shBrushXml.js' type='text/javascript'/>
<script src='https://sites.google.com/site/english0815/Home/syntaxhighlighter/shBrushCss.js' type='text/javascript'/>
<script type='text/javascript'>
SyntaxHighlighter.all()
</script>
4. 在網誌裡新增程式碼
<pre class="brush: xml">
public class HelloWorld {

    public static void main (String[] args) {
        System.out.println("Hello, world!");
    }
}
</pre>
以下為顯示結果
public class HelloWorld {

    public static void main (String[] args) {
        System.out.println("Hello, world!");
    }
}
5. 如遇到HTML語法<或>符號,需透過以下網址轉換語法,才可以正常顯示
HTML Encoder

6.1. 你可能會發現垂直捲軸會被顯示在框架中,可以修改syntaxhighlighter_3.0.83\styles\shCore.css來隱藏垂直捲軸
.syntaxhighlighter {
  width: 100% !important;
  margin: 1em 0 1em 0 !important;
  position: relative !important;
  overflow:auto !important;
  font-size: 12px;
}
to
.syntaxhighlighter {
  width: 100% !important;
  margin: 1em 0 1em 0 !important;
  position: relative !important;
  overflow-x:auto !important;
  overflow-y:hidden !important;
  font-size: 12px;
}
6.2. 你可能會發現框架中會有多餘的空白出現,可以修改syntaxhighlighter_3.0.83\styles\shCore.css來去除這些空白行
.syntaxhighlighter {
.syntaxhighlighter table td.gutter .line {
  text-align: right !important;
  padding: 0 0.5em 0 1em !important;
}
}
to
.syntaxhighlighter {
.syntaxhighlighter table td.gutter .line {
  text-align: right !important;
  padding: 0 5px !important;
}
}
7. 參考資料
How To Add Syntax Highlighter for Blogger/Blogspot
Extra Lines using SyntaxHighlighter for Chrome Only?

Blogger嵌入程式碼 - Google Code Prettify & CSS Block

1. 版面配置-> 新增小工具-> 選擇"HTML/JavaScript"小工具
插入以下Google Code Prettify的程式,此功能只會在程式碼周圍加上外框並填上顏色,如果想要底色填滿,需要再加入CSS Block的程式碼
<script src="//google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
2. 版面配置-> 新增小工具-> 選擇"HTML/JavaScript"小工具
插入CSS Block的程式
<style>
.post .codeblock {
display: block; /* fixes a strange ie margin bug */
font-family: Courier New;
font-size: 10pt;
overflow:auto;
background: #f0f0f0 url(data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAASwCAYAAAAt7rCDAAAABHNCSVQICAgIfAhkiAAAAQJJREFUeJzt0kEKhDAMBdA4zFmbM+W0upqFOhXrDILwsimFR5pfMrXW5jhZr7PwRlxVX8//jNHrGhExjXzdu9c5IiIz+7iqVmB7Hwp4OMa2nhhwN/PRGEMBh3Zjt6KfpzPztxW9MSAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzB8HS+J9kUTvzEDMwAAAABJRU5ErkJggg==) left top repeat-y;
border: 1px solid #ccc;
padding: 10px 10px 10px 21px;
max-height:1000px;
line-height: 1.2em;
}
</style>
3. 在網誌裡新增程式碼
<pre class='codeblock'>
public class HelloWorld {

    public static void main (String[] args) {
        System.out.println("Hello, world!");
    }
}
</pre>
以下為顯示結果
public class HelloWorld {

    public static void main (String[] args) {
        System.out.println("Hello, world!");
    }
}
4. 如遇到HTML語法<或>符號,需透過以下網址轉換語法,才可以正常顯示。
HTML Encoder

5. 參考資料
在網頁中嵌入顯示程式碼:CSS Block
在網頁中嵌入顯示程式碼:Google Code Prettify

2014年2月8日 星期六

半馬回憶錄

是命運的捉弄,亦或是冥冥之中,有無形力量的安排,我報名了人生第一場馬拉松。畢竟是第一次參加馬拉松賽事,也上網問google先生做了一些功課,比賽當天帶著興奮又緊張的心情來到會場,在報名完也熱身完後,就萬事俱備只缺鳴響。槍響的那一刻,開始試著在人群中調整步伐,因為太多人擠在一起像沙丁魚一樣,所以我開啟了Turbo模式跑離人群,等到周遭的人較稀疏後,便轉換為定速巡航模式,開始了我的半馬之旅。

由於平常的練習,這個速度還在under control,有點像是蜻蜓點水般大跨步,漸漸的眼前的人一個個被我超越,我超越一個M、兩個M和好多好多個M,這些M算一算應該有比中華電信的五十M還要多。大概過了8公里後,不幸的事還是發生了,右腳膝蓋開始隱隱作痛,我的膝蓋開始無法支撐我的跑速,只好被迫切換成凌波微步放慢速度,膝蓋的疼痛感才慢慢減輕。

就在調整步伐之計,一個M從後面呼嘯而過,此時的心情百感交集,我拚了命追趕卻徒勞無功,就像眼前有個正妹在挑逗你,但卻硬不起來的感覺,接著愈來愈多人呼嘯而過,我試著加快速度,卻心有餘而力不足。正好對面一台公車迎面而來,心裡突然有股念頭想跳上公車結束這一切,或者希望路旁正好有個紅色電話亭,我可以因此而穿上披風飛回終點。

回程到了大甲溪橋,這是第一次覺得大甲溪橋有如萬里長城一般,怎麼看不到終點阿!途中有一些民眾為我們加油打氣,我也對著他們比出必勝的手勢,雖然這時候下半身已經不是自己的。心裡想著我不能這樣而一蹶不振,開始從音樂中找尋自己的節奏,用音樂來麻醉自己神經,加上超人般意志力的支持,就這樣我終於跑到了終點,結束了這場半馬之旅。

跑完這次半程馬拉松,心中有一些新的體悟,我想這應該是跑過的人才會懂的。
1. 有時候放慢腳步注意周遭,路上會有一些意想不到的美景。
2. 超越了幾個M並不重要,重要的是找一個M,願意和你一起跑到終點。
3. 不要太在意別人超越你,按照自己的步伐節奏,終點終究會到來。
4. 當遇到挫折時,試著用不同的方式去面對,一定可以克服挫折勇往直前。
5. 山不在高,有仙則名;水不在深,有龍則靈;馬不在快,跑完就行。

2014年1月4日 星期六

看見台灣

第一次,這是第一次看電影等到螢幕轉暗後,才有人準備起座離去,雖然在座的人數不算太多,也不確定大家是否都睡著了,但很確定的是我還醒著。

看見台灣,一部記錄台灣美景的記錄片,如果你不曾挑戰過百嶽,如果你不曾環島旅行,可以走進戲院去看見台灣,它可以帶著你去俯瞰台灣高山的雄偉,去體驗台灣環海的美景。

看見台灣,記錄著台灣土地破壞與環境汙染最真實的一面,環境保護的議題從以前一直存在著,但是多數的人看不見,少數的人假裝沒看見,也許這部電影可以引起共鳴,喚起台灣人的環保意識,不過無法改變的是,經濟發展與環境保護的關係永遠存在著矛盾與衝突。

聽著吳念真的旁白唸著,台灣就像我們的母親一樣,誰都沒有權力去褻瀆台灣的美,因為我們只是短暫的停留,因為我們只是個過客。