Hi! I’m clsung

Hi! I’m clsung

clsung’s blog site, or you can call me AlanSung

Hi! I’m clsung RSS Feed
 
 
 
 

[Task] Suffix Array another Bug resolved

前言就是上個 Task 囉,假設句子為

您終於回來了
您終於回來了
您終於回來了
我終於回來了

那麼程式原來的 output 是

您終於回來了,3
終於回來了,4

而原來的 bug 版本跑過之後,會將
終於回來了,4
吃掉,只剩第一個,因為做了修正。修改之後就好了 :D

原先的:

for (j = 1; j < wi; j++) {
        // This function check "abcd,4,2" and "bcd,3,2"
        // then set "bcd,3,2" to "bcd,3,0"
        if (word_freq[j].wend == word_freq[j-1].wend) {
            word_freq[j].freq = 0;
        }
    }

改過之後的:

for (j = 1, i = j - 1; j < wi; j++) {
        // This function check "abcd,4,2" and "bcd,3,2"
        // then set "bcd,3,2" to "bcd,3,0"
        if (word_freq[j].wend == word_freq[i].wend && word_freq[j].freq == word_freq[i].freq) {
            word_freq[j].freq = 0;
        } else
            i = j; // j will become j+1 later (for loop)
    }

結論是,這種有大量 input/output 的程式還真難 debug,尤其在結果大部份都是合理的情況下,更是難以分辨。

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • funp
  • Haohao
  • Hemidemi
  • Live
  • MisterWong
  • TwitThis
  • udn

Leave a Reply

噗浪:

  • clsung 說 來睡,這裡果然溫暖好多 9 hours 前
  • clsung 說 冷 12 hours 前
  • clsung 說 本週六要上班.... 累 17 hours 前

分類

Flickr

    clsung. Get yours at bighugelabs.com/flickr

Blogroll

    馬的警總回來了
Creative Commons Attribution-NonCommercial-ShareAlike 2.5 Taiwan
Creative Commons Attribution-NonCommercial-ShareAlike 2.5 Taiwan