zoukankan      html  css  js  c++  java
  • CF22A Second Order Statistics

    Second Order Statistics (CF22A) 题解

    这是一道CF的题目(Code Forces 22A)

    题目(英文):

    Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.

    输入格式:

    The first input line contains integer nn ( 1<=n<=1001<=n<=100 ) — amount of numbers in the sequence. The second line contains nn space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.

    输出格式:

    If the given sequence has the second order statistics, output this order statistics, otherwise output NO.

    题意翻译(中文)
    给定一个数组,输出其中第二小的整数(相等的整数只计算一次)
    输入:
    第一行,一个整数n(1<=n<=100),表示数组长度
    第二行,n个绝对值小于100的整数。
    输出:
    一行。如果该数组存在第二小整数,则输出。如果不存在,则输出NO.

    题目不难理解

    主要的是排序。(Sort快排一遍加个特判不就好了吗?)

    过滤第一小的数,用剩下的数排一次。

    任何一个伟大的思想,都有一个微不足道的开始。

    < 如果Sort不会,下有参考文献 >

     放代码:

    #include<bits/stdc++.h>
    using namespace std;
    int n,a[107],l;
    int main(){
        scanf("%d",&n);
        for(int i=1;i<=n;i++)scanf("%d",&a[i]);
        sort(a+1,a+n+1);
        l=a[1];
        for(int i=1;i<=n;i++){
            if(a[i]!=l){
                printf("%d
    ",a[i]);
                return 0;
            }
        }
        printf("NO
    ");
        return 0;
    }
    

      

    参考文献:

      Sort百度百科

    排序算法总结

    OVER!


    写于2019年1月2日
    作者:WSJ
  • 相关阅读:
    SQL单表查询
    SQL基础
    python生成器yield和send
    python模块
    python异常
    python单例设计模式
    python类方法、类属性和静态方法
    python继承
    react native window下的环境搭建和调试方案
    打通前后端全栈开发node+vue进阶【课程学习系统项目实战详细讲解】(3):用户添加/修改/删除 vue表格组件 vue分页组件
  • 原文地址:https://www.cnblogs.com/wangshengjun/p/cf22A.html
Copyright © 2011-2022 走看看