zoukankan      html  css  js  c++  java
  • 算法提高 第二大整数

    http://lx.lanqiao.org/problem.page?gpid=T211

     
    算法提高 第二大整数  
    时间限制:1.0s   内存限制:512.0MB
        
    问题描述
      编写一个程序,读入一组整数(不超过20个),当用户输入0时,表示输入结束。然后程序将从这组整数中,把第二大的那个整数找出来,并把它打印出来。说明:(1)0表示输入结束,它本身并不计入这组整数中。(2)在这组整数中,既有正数,也可能有负数。(3)这组整数的个数不少于2个。
      输入格式:输入只有一行,包括若干个整数,中间用空格隔开,最后一个整数为0。
      输出格式:输出第二大的那个整数。
      输入输出样例
    样例输入
    5 8 -12 7 0
    样例输出
    7
     
    分析:
     
    简单的排序。
     
    AC代码:
     
     1 #include <stdio.h>
     2 #include <algorithm>
     3 #include <iostream>
     4 #include <string.h>
     5 #include <string>
     6 #include <math.h>
     7 #include <stdlib.h>
     8 #include <queue>
     9 #include <stack>
    10 #include <set>
    11 #include <map>
    12 #include <list>
    13 #include <iomanip>
    14 #include <vector>
    15 #pragma comment(linker, "/STACK:1024000000,1024000000")
    16 #pragma warning(disable:4786)
    17 
    18 using namespace std;
    19 
    20 const int INF = 0x3f3f3f3f;
    21 const int Max = 10000 + 10;
    22 const double eps = 1e-8;
    23 const double PI = acos(-1.0);
    24 
    25 int main()
    26 {
    27     int a[25] , i = 0, temp;
    28     while(scanf("%d",&a[i ++]))
    29     {
    30         if(a[i - 1] == 0)
    31         {
    32             if(i <= 1)
    33                 return 0;
    34             sort(a , a + i);
    35             if(a[i - 1] == 0)
    36                 printf("%d
    ",a[i - 3]);
    37             else
    38                 printf("%d
    ",a[i - 2]);
    39             break;
    40         }
    41         else
    42             continue;
    43     }
    44     return 0;
    45 }
    View Code
  • 相关阅读:
    Swagger2 添加HTTP head参数
    获取枚举类型描述
    JS设置cookie、读取cookie、删除cookie
    ES6中Promise的入门(结合例子)
    阮一峰的ES6---Promise对象
    model_util.py
    IfcSpatialElementType
    labelme coco
    python opencv KeyPoint
    IfcSpatialZoneType
  • 原文地址:https://www.cnblogs.com/jeff-wgc/p/4450765.html
Copyright © 2011-2022 走看看