langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
|
|
@ -0,0 +1,24 @@
|
|||
let input_line_opt ic =
|
||||
try Some (input_line ic)
|
||||
with End_of_file -> None
|
||||
|
||||
let cmp s1 s2 =
|
||||
try ignore(s1.[String.length s2]); 1 (* s1 is longer *)
|
||||
with _ ->
|
||||
try ignore(s2.[String.length s1]); -1 (* s2 is longer *)
|
||||
with _ -> 0 (* both same length *)
|
||||
|
||||
let () =
|
||||
let ic = open_in Sys.argv.(1) in
|
||||
let rec loop longest acc =
|
||||
match input_line_opt ic with
|
||||
| Some line ->
|
||||
( match cmp line longest with
|
||||
| 1 -> loop line (line ^ "\n")
|
||||
| 0 -> loop line (acc ^ line ^ "\n")
|
||||
| _ -> loop longest acc )
|
||||
| None ->
|
||||
close_in ic;
|
||||
print_string acc
|
||||
in
|
||||
loop "" ""
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
read: procedure options (main); /* 18 January 2012. */
|
||||
declare line character (100) varying controlled;
|
||||
declare text character (100) varying;
|
||||
declare max_length fixed binary;
|
||||
declare in file input;
|
||||
|
||||
on endfile (in) go to done;
|
||||
|
||||
open file (in) title ('/readline.pli,type(text),recsize(100)');
|
||||
|
||||
max_length = 0;
|
||||
do forever;
|
||||
get file (in) edit (text) (L);
|
||||
put skip list (text);
|
||||
if length (text) > max_length then
|
||||
do;
|
||||
max_length = length(text);
|
||||
/* empty the stack */
|
||||
do while (allocation(line) > 0);
|
||||
free line;
|
||||
end;
|
||||
allocate line;
|
||||
line = text;
|
||||
end;
|
||||
else if length(text) = max_length then
|
||||
do;
|
||||
allocate line;
|
||||
line = text;
|
||||
end;
|
||||
end;
|
||||
|
||||
done:
|
||||
put skip list (max_length || ' is the length of the longest line(s)' );
|
||||
do while (allocation(line) > 0);
|
||||
put skip list (line);
|
||||
free line;
|
||||
end;
|
||||
|
||||
end read;
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
program LongestStringChallenge_1(input, output);
|
||||
|
||||
var
|
||||
Line: string;
|
||||
Lines: array of string;
|
||||
position, len: integer;
|
||||
|
||||
begin
|
||||
if not eoln(input) then
|
||||
begin
|
||||
len := 1;
|
||||
position := 0;
|
||||
readln (line);
|
||||
setlength(lines, len);
|
||||
lines[position] := line;
|
||||
while not eoln(input) do
|
||||
begin
|
||||
readln (line);
|
||||
if length(line) = length(lines[0]) then
|
||||
begin
|
||||
inc(position);
|
||||
inc(len);
|
||||
setlength(lines, len);
|
||||
lines[position] := line;
|
||||
end;
|
||||
if length(line) > length(lines[0]) then
|
||||
begin
|
||||
position := 0;
|
||||
len := 1;
|
||||
setlength(lines, 1);
|
||||
lines[0] := line;
|
||||
end;
|
||||
end;
|
||||
for position := low(lines) to high(lines) do
|
||||
writeln (lines[position]);
|
||||
end;
|
||||
end.
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
program LongestStringChallenge_2(input, output);
|
||||
|
||||
{$mode ObjFPC}
|
||||
{$rangechecks on}
|
||||
|
||||
uses
|
||||
SysUtils;
|
||||
|
||||
var
|
||||
Line: ANSIstring;
|
||||
Lines: array of ANSIstring;
|
||||
position: integer;
|
||||
tester: char;
|
||||
|
||||
begin
|
||||
if not eoln(input) then
|
||||
begin
|
||||
readln (line);
|
||||
position := 0;
|
||||
setlength(lines, 1);
|
||||
lines[0] := line;
|
||||
while not eoln(input) do
|
||||
begin
|
||||
readln (line);
|
||||
try
|
||||
tester := lines[0][length(line)];
|
||||
try
|
||||
tester := line[length(lines[0])];
|
||||
inc(position);
|
||||
setlength(lines, succ(position));
|
||||
lines[position] := line;
|
||||
except
|
||||
end;
|
||||
except
|
||||
position := 0;
|
||||
setlength(lines, 1);
|
||||
lines[0] := line;
|
||||
end;
|
||||
end;
|
||||
for position := low(lines) to high(lines) do
|
||||
writeln (lines[position]);
|
||||
end;
|
||||
end.
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
my $l = ''; # Sample longest string seen.
|
||||
my $a = ''; # Accumulator to save longest strings.
|
||||
|
||||
while $*IN.get -> $s {
|
||||
my $n = "$s\n";
|
||||
if $n.substr($l.chars) { # Is new string longer?
|
||||
$a = $l = $n; # Reset accumulator.
|
||||
}
|
||||
elsif !$l.substr($n.chars) { # Same length?
|
||||
$a ~= $n; # Accumulate it.
|
||||
}
|
||||
}
|
||||
print $a;
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
int main(int argc, array argv)
|
||||
{
|
||||
string longest = "";
|
||||
foreach(Stdio.stdin.line_iterator();; string line)
|
||||
{
|
||||
if( sizeof(indices(line) - indices(longest)))
|
||||
{
|
||||
while(!zero_type(remove_call_out(write)));
|
||||
|
||||
longest = line;
|
||||
call_out(write, 0, line+"\n");
|
||||
}
|
||||
else if( !sizeof(indices(longest) - indices(line)))
|
||||
{
|
||||
call_out(write, 0, line+"\n");
|
||||
}
|
||||
}
|
||||
call_out(exit, 0.01, 0);
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
Procedure.i ConsoleWrite(t.s) ; compile using /CONSOLE option
|
||||
OpenConsole()
|
||||
PrintN (t.s)
|
||||
CloseConsole()
|
||||
ProcedureReturn 1
|
||||
EndProcedure
|
||||
|
||||
Procedure.i StdOut(t.s) ; compile using /CONSOLE option
|
||||
OpenConsole()
|
||||
Print(t.s)
|
||||
CloseConsole()
|
||||
ProcedureReturn 1
|
||||
EndProcedure
|
||||
|
||||
|
||||
DataSection
|
||||
s:
|
||||
Data.s "a"
|
||||
Data.s "bb"
|
||||
Data.s "ccc"
|
||||
Data.s "ddd"
|
||||
Data.s "ee"
|
||||
Data.s "f"
|
||||
Data.s "ggg"
|
||||
Data.s "~" ; the tilda is only to keep the code compact
|
||||
e: ; and easy to understand
|
||||
EndDataSection
|
||||
|
||||
l$="" ; memory allocation for strings is automatic
|
||||
a$="" ; in fact these two lines are unnecessary
|
||||
|
||||
Restore s
|
||||
|
||||
Repeat
|
||||
Read.s s$
|
||||
If s$="~":Break:EndIf
|
||||
s$+#CRLF$
|
||||
s=Len(s$):l=Len(l$) ; using s$ allows the use of s as an integer type
|
||||
If s>l :l$=s$:a$=l$
|
||||
ElseIf s=l :a$+s$
|
||||
EndIf
|
||||
Forever
|
||||
|
||||
StdOut(a$)
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
sqliteconnect #mem, ":memory:" ' Create in memory DB
|
||||
#mem execute("CREATE TABLE data(str)") ' And fields to hold the string data
|
||||
|
||||
strings$ = "a bb ccc ddd ee f ggg" ' The given string data
|
||||
|
||||
while word$(strings$,i + 1," ") <> ""
|
||||
i = i + 1
|
||||
#mem execute("INSERT INTO data VALUES('";word$(strings$,i," ");"')") ' insert the strings in to the DB
|
||||
wend
|
||||
|
||||
#mem execute("SELECT length(str) as leng, str FROM data ORDER BY leng desc,str") ' pull data in reverse lenght sequence
|
||||
WHILE #mem hasanswer()
|
||||
#row = #mem #nextrow()
|
||||
leng = #row leng()
|
||||
str$ = #row str$()
|
||||
print leng;" ";str$ ' print the data
|
||||
WEND
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
strings$ = "a bb ccc ddd ee f ggg" ' The given string data
|
||||
|
||||
while word$(strings$,numWords + 1," ") <> "" ' Count the words
|
||||
numWords = numWords + 1
|
||||
wend
|
||||
|
||||
dim string$(numWords) ' Dimension the string with the word cound
|
||||
for j = 1 to numWords
|
||||
string$(j) = word$(strings$,j," ") ' put the words from the string into the string array
|
||||
next j
|
||||
|
||||
h$ = "1"
|
||||
while h$ <> "" ' The good old simple bubble sort
|
||||
h$ = ""
|
||||
for i = 1 to numWords -1
|
||||
if len(string$(i)) < len(string$(i+1)) then ' sort by length descending
|
||||
h$ = string$(i)
|
||||
string$(i) = string$(i+1)
|
||||
string$(i+1) = h$
|
||||
end if
|
||||
next i
|
||||
wend
|
||||
|
||||
for i = 1 to numWords
|
||||
print len(string$(i));" ";string$(i) ' print out the words in length descending sequence
|
||||
next i
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
<xsl:output indent="yes" encoding="UTF-8" omit-xml-declaration="yes" />
|
||||
<xsl:template match="/*">
|
||||
<t><xsl:copy-of select="for $l in max( for $s in s return string-length($s))
|
||||
return s[string-length(.) eq $l]" /></t>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<t>
|
||||
<s>a</s>
|
||||
<s>bb</s>
|
||||
<s>ccc</s>
|
||||
<s>ddd</s>
|
||||
<s>ee</s>
|
||||
<s>f</s>
|
||||
<s>ggg</s>
|
||||
</t>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<t>
|
||||
<s>ccc</s>
|
||||
<s>ddd</s>
|
||||
<s>ggg</s>
|
||||
</t>
|
||||
Loading…
Add table
Add a link
Reference in a new issue