Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
46
Task/ABC-Problem/Objeck/abc-problem.objeck
Normal file
46
Task/ABC-Problem/Objeck/abc-problem.objeck
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
class Abc {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
blocks := ["BO", "XK", "DQ", "CP", "NA",
|
||||
"GT", "RE", "TG", "QD", "FS",
|
||||
"JW", "HU", "VI", "AN", "OB",
|
||||
"ER", "FS", "LY", "PC", "ZM"];
|
||||
|
||||
IO.Console->Print("\"\": ")->PrintLine(CanMakeWord("", blocks));
|
||||
IO.Console->Print("A: ")->PrintLine(CanMakeWord("A", blocks));
|
||||
IO.Console->Print("BARK: ")->PrintLine(CanMakeWord("BARK", blocks));
|
||||
IO.Console->Print("book: ")->PrintLine(CanMakeWord("book", blocks));
|
||||
IO.Console->Print("treat: ")->PrintLine(CanMakeWord("treat", blocks));
|
||||
IO.Console->Print("COMMON: ")->PrintLine(CanMakeWord("COMMON", blocks));
|
||||
IO.Console->Print("SQuAd: ")->PrintLine(CanMakeWord("SQuAd", blocks));
|
||||
IO.Console->Print("CONFUSE: ")->PrintLine(CanMakeWord("CONFUSE", blocks));
|
||||
}
|
||||
|
||||
function : CanMakeWord(word : String, blocks : String[]) ~ Bool {
|
||||
if(word->Size() = 0) {
|
||||
return true;
|
||||
};
|
||||
|
||||
c := word->Get(0)->ToUpper();
|
||||
for(i := 0; i < blocks->Size(); i++;) {
|
||||
b := blocks[i];
|
||||
if(<>(b->Get(0)->ToUpper() <> c & b->Get(1)->ToUpper() <> c)) {
|
||||
Swap(0, i, blocks);
|
||||
new_word := word->SubString(1, word->Size() - 1);
|
||||
new_blocks := String->New[blocks->Size() - 1];
|
||||
Runtime->Copy(new_blocks, 0, blocks, 1, blocks->Size() - 1);
|
||||
if(CanMakeWord(new_word, new_blocks)) {
|
||||
return true;
|
||||
};
|
||||
Swap(0, i, blocks);
|
||||
};
|
||||
};
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function : native : Swap(i : Int, j : Int, arr : String[]) ~ Nil {
|
||||
tmp := arr[i];
|
||||
arr[i] := arr[j];
|
||||
arr[j] := tmp;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue