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.
+-----------+------------+ | INPUT.TXT | OUTPUT.TXT | +-----------+------------+ |4 |1 6 | |aabbcc |z | |klm |ns | |z |klm | |ns |aabbcc | +-----------+------------+
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.
#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; }
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