Algorithm to increase the second large integer time limit: 1.0s memory limit: 512.0MBThe 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 <stdio.h>2 intMain () {3 inta[ -];4 intk=0;//Array subscript5 intx;6 while(~SCANF ("%d",&x)) {7 if(x==0)8 Break;9 ElseTena[k++]=x; One } A /*Bubble Descending*/ - for(intI=0; i<k-1; i++){ - for(intj=0; j<k-1-I.; J + +){ the if(a[j]<a[j+1]){ - intt =A[j]; -A[J] = a[j+1]; -a[j+1] =T; + } - } + } Aprintf"%d", a[1]); at}
C language · Second largest integer