66 lines
1.3 KiB
Text
66 lines
1.3 KiB
Text
use System.IO.File;
|
|
use Collection;
|
|
|
|
class Abbreviations {
|
|
function : Main(args : String[]) ~ Nil {
|
|
if(args->Size() = 1) {
|
|
Go(args[0]);
|
|
};
|
|
}
|
|
|
|
function : Go(file : String) ~ Nil {
|
|
reader := FileReader->New(file);
|
|
leaving {
|
|
reader->Close();
|
|
};
|
|
|
|
cache := StringMap->New();
|
|
line := reader->ReadString();
|
|
while(line <> Nil) {
|
|
if(line->Size() > 0) {
|
|
days := line->Split(" ");
|
|
|
|
cache->Empty();
|
|
each(i : days) {
|
|
day := days[i];
|
|
cache->Insert(day, IntHolder->New(1));
|
|
};
|
|
|
|
if(cache->Size() < 7) {
|
|
" ∞ {$line}"->PrintLine();
|
|
};
|
|
|
|
len := 1;
|
|
while(true) {
|
|
cache->Empty();
|
|
each(i : days) {
|
|
day := days[i];
|
|
sd : String;
|
|
if(len >= day->Size()) {
|
|
sd := day;
|
|
}
|
|
else {
|
|
sd := day->SubString(len);
|
|
};
|
|
|
|
count := cache->Find(sd)->As(IntHolder);
|
|
if(count = Nil) {
|
|
cache->Insert(sd, IntHolder->New(1));
|
|
}
|
|
else {
|
|
count->Inc();
|
|
};
|
|
};
|
|
|
|
if(cache->Size() = 7) {
|
|
"{$len} {$line}"->PrintLine();
|
|
break;
|
|
};
|
|
len += 1;
|
|
};
|
|
};
|
|
|
|
line := reader->ReadString();
|
|
};
|
|
}
|
|
}
|