Ordered words: Difference between revisions

Added XPL0 example.
(Add COBOL)
(Added XPL0 example.)
Line 4,880:
<pre>
The 16 ordered words with the longest length (6) are:
abbott
accent
accept
access
accost
almost
bellow
billow
biopsy
chilly
choosy
choppy
effort
floppy
glossy
knotty
</pre>
 
=={{header|XPL0}}==
<lang XPL0>string 0; \use zero-terminated strings
int Dict(26000); \pointers to words (enough for unixdict.txt)
int DictSize; \actual number of pointers in Dict
int DI, I, Ch, Ch0, MaxLen, Pass;
char Word;
def LF=$0A, CR=$0D, EOF=$1A;
 
[FSet(FOpen("unixdict.txt", 0), ^I); \load dictionary into Dict
OpenI(3); \assume alphabetical order and all lowercase
DI:= 0; \ignore non-alpha characters: 0..9, ' and &
repeat Dict(DI):= Reserve(0); \get pointer to memory used to store Word
Word:= Dict(DI);
I:= 0;
loop [repeat Ch:= ChIn(3) until Ch # CR; \remove possible CR
if Ch=LF or Ch=EOF then quit;
Word(I):= Ch;
I:= I+1;
];
Word(I):= 0; \terminate Word string
I:= Reserve(I+1); \reserve memory used for Word
DI:= DI+1; \next dictionary entry
until Ch = EOF;
DictSize:= DI;
 
MaxLen:= 0;
for Pass:= 1 to 2 do
[DI:= 0;
repeat Word:= Dict(DI);
I:= 0; Ch0:= 0;
loop [Ch:= Word(I);
if Ch = 0 then
[if I > MaxLen then MaxLen:= I;
if I=MaxLen & Pass=2 then
[Text(0, Word); CrLf(0)];
quit;
];
if Ch < Ch0 then quit;
Ch0:= Ch;
I:= I+1;
];
DI:= DI+1;
until DI >= DictSize;
];
]</lang>
 
{{out}}
<pre>
abbott
accent
772

edits