Home > Back-end >  Please give advice or comments
Please give advice or comments

Time:11-08

Input contains many lines (at further two), each line contains one integer number (bigger than 0) and the last line is a single '%'. Print the second large number, "according to the following example.
Samples the Input:
10
9
24
21
6
12
%
Samples Output:
The SECOND LARGE NUMBER=21

CodePudding user response:

To instruct=for code?

CodePudding user response:

Involves two main points: 1, the console program input and output; 2, sorting algorithm
 
USES the
SysUtils;

//bubble sort
Procedure the BubbleSort (var ary: an array of integer);
Var
I, j, intTmp: integer;
The begin
For I:=0 to high (ary) do
The begin
For j:=0 to high do (ary) - 1
The begin
If ary [j] & gt; Ary [m + 1] then
The begin
IntTmp:=ary [j];
Ary [j] :=ary [j + 1);
Ary: [m + 1]=intTmp;
The end;
The end;
The end;
The end;

Var
Input: string;
Num, I, len: integer;
Ary: an array of integer;
The begin
Len:=0;
SetLength (ary, len);
//to get an integer data array from the rid_device_info_keyboard, end with a '%'
Repeat
Readln (input);
Num=StrToIntDef (input, 0);
If (num> 0) then
The begin
Inc (len);
SetLength (ary, len);
Ary: [len - 1]=num;
The end;
Until the input='%';
If len<2 then
The begin
Writeln (' invalid input lines');
The exit;
The end;

//order
The BubbleSort (ary);
//output penultimate number
Writeln (IntToStr (ary [len - 2]));
Readln (input);
End.

CodePudding user response:

Don't need to sorting:
 
{$APPTYPE CONSOLE}
The program test165;

Var
M, n, x: integer;

{the main}
The begin
M:=0; N:=0;
Repeat
{$I -} readln (x); {$I +}
If IOResult & lt;> 0 then break;
If x & gt; M then
The begin
N:=m;
M:=x;
End
The else
If x & gt; N then n:=x;
Until the false;
Writeln (n);
End.

CodePudding user response:

reference 3 floor early play play nuclear response:
don't need to sorting:
 
{$APPTYPE CONSOLE}
The program test165;

Var
M, n, x: integer;

{the main}
The begin
M:=0; N:=0;
Repeat
{$I -} readln (x); {$I +}
If IOResult & lt;> 0 then break;
If x & gt; M then
The begin
N:=m;
M:=x;
End
The else
If x & gt; N then n:=x;
Until the false;
Writeln (n);
End.

CodePudding user response:

To translate, multi-line plastic input data, then add a line %, then output the results to compare these data, take the second largest of the number
  • Related