IOI'95: Batch Program Example
#
Batch Program Example

## Sorting Trucks

The first line of file `INPUT.TXT` contains
the number *n* of trucks to be sorted (1<=*n*<=10).
Each of the following *n* lines describes one truck
by a string of at least 1 and most 20 lowercase letters
(from ``a`' to ``z`').
The weight of a truck is given by the length of its string.
All trucks differ in weight.

On the first line of file `OUTPUT.TXT`
your program should write the weight of the lightest
and the weight of the heaviest truck in the input file.
On the following *n* lines it should write the input strings in
order of increasing weight, one string per line.

## Example Input and Output

The figure below gives an example input file with four trucks,
and the corresponding output file.
+-----------+------------+
| INPUT.TXT | OUTPUT.TXT |
+-----------+------------+
|4 |1 6 |
|aabbcc |z |
|klm |ns |
|z |klm |
|ns |aabbcc |
+-----------+------------+

### Batch Program in Turbo Pascal:

var inp, out: text;
n, i, wl, wh: integer;
s: array [1..10] of string[20];
begin
Assign(inp, 'INPUT.TXT') ; reset(inp) ;
Assign(out, 'OUTPUT.TXT') ; rewrite(out) ;
readln(inp, n) ;
for i := 1 to n do readln(inp, s[i]) ;
...
writeln(out, wl, ' ', wh) ;
for i := 1 to n do writeln(out, s[i]) ;
close(out)
end.

### Batch Program in Turbo C++:

#include <fstream.h>
ifstream inp ("INPUT.TXT");
ofstream out ("OUTPUT.TXT");
int n, i, wl, wh;
char s[11][21];
int main()
{ inp >> n;
for (i=1; i<=n; ++i) inp >> s[i];
...
out << wl << ' ' << wh << '\n';
for (i=1; i<=n; ++i) out << s[i] << '\n';
return 0;
}

### Batch Program in QuickBasic:

OPEN "INPUT.TXT" FOR INPUT AS #1
OPEN "OUTPUT.TXT" FOR OUTPUT AS #3
DEFINT A-Z
DIM s(1 TO 10) AS STRING
INPUT #1, n
FOR i = 1 TO n
INPUT #1, s
NEXT i
...
PRINT #3, wl; wh
FOR i = 1 TO n
PRINT #3, s
NEXT i
END

IOI 95