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
  • 相关阅读:
    A3纸双面打印对折页设置方法
    BAD SYSTEM CONFIG INFO蓝屏解决办法
    局域网内Win7系统怎么开启远程桌面
    word批量删除换行符
    excel复制到word,表格格式错乱解决办法
    word取消回车自动编号
    被深信服上网行为管理器AC拒绝的操作如何正常访问
    震旦AD248复印机如何复印身份证正反面
    Win10开机后黑屏需强制关机再开机才能进桌面怎么办
    Windows已经发现此文件有一个问题
  • 原文地址:https://www.cnblogs.com/wangshengjun/p/cf22A.html
Copyright © 2011-2022 走看看