KWIC(Keyword in Context) Problem(Solution)

這是這學期修習高等軟體程式設計的第一次程式作業。

題目介紹

Input:
The C Programming Language
The Cat in the Hat

Cyclic Shift:

The C Programming Language

C Programming Language The
Programming Language The C

The Cat in the Hat
Cat in the Hat The

Output(Ordered):

C Programming Language The

Cat in the Hat The
Hat The Cat in the
in the Hat The Cat
Language The C Programming
Programming Language The C
The C Programming Language
The Cat in the Hat
the Hat The Cat in

解題作法

  • I/O
  • 使用string的split切割輸入的input為string[],並轉存為arrayList(較彈性)
  • raiseCombinationSet:傳入input分割出的WordSet及combinationSet的container,透過此function產生所有該wordSet的排列(根據KWIS規則)並存至combinationSet中。
  • 製造一個WordSet的Class並implements Comparable,以便使用Arrays.Sort這個API來排序,並客製化我們的比較規則(compareTo)。
  • 製作一方法,將存放所有排列的combinationSet中的wordSet轉成WordSet這個class並傳回array,以便使用Arrays.Sort。
## 原始碼