Algorithm to increase the second large integer time limit: 1.0s memory limit: 512.0MB The problem description writes a program that reads in a set of integers (no more than 20), and when the user enters 0 o'clock, the input ends. The program will then find the second largest integer from this set of integers and print it out. Note: (1) 0 indicates the end of the input, which itself is not counted in this set of integers. (2) In this set of integers, both positive and negative numbers are possible. (3) The number of integers in this group is not less than 2.
Input format: Enter only one line, including several integers, separated by a space, the last integer is 0.
Output format: Output the second largest integer.
Input/Output Sample sample input 5 8-12 7 0 Sample Output 7
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 inta[ A];7 intcmpintXinty)8 {9 returnX>y;Ten } One intMain () A { - intx,i; - intR=0; the while(~SCANF ("%d",&x)) - { - if(x==0) - Break; +a[r++]=x; - } +Sort (a,a+r,cmp); Aprintf"%d\n", a[1]); at return 0; -}
Algorithm to increase the second largest integer