Algorithm to increase the second largest integer

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.