Longest string challenge: Difference between revisions
Content deleted Content added
Go solution |
|||
Line 605: | Line 605: | ||
return -1; |
return -1; |
||
}</lang> |
}</lang> |
||
=={{header|PL/I}}== |
|||
<lang PL/I> |
|||
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; |
|||
</lang> |
|||
output (the above file plus the following 3 lines): |
|||
<pre> |
|||
74 is the length of the longest line(s) |
|||
put skip list (max_length || ' is the length of the longest line(s)' ); |
|||
/* Read lines of a file, and print the longest. (If there is more than */ |
|||
</pre> |
|||
=={{header|Python}}== |
=={{header|Python}}== |