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
  • 相关阅读:
    在虚拟机中的Ubuntu搭建java开发环境
    Flask08 包含(include)、继承(extends)、宏???、模板中变量的来源、利用bootstrap构建自己的网页结构
    Flask07 Jinja2模板测试器、控制语句IF/FOR、变量/块 赋值、作用域、块级作用域
    Flask06 地址约定、利用falsk提供的方法渲染模板
    Flask05 cookie、类视图、方法视图、自己的404页面
    Flask04 后台获取请求数据、视图函数返回类型、前台接受响应数据
    Flask03 路由控制(转换器)、反转、请求方法控制
    Flask02 路由的书写、蓝图、利用蓝图实现url前缀、利用蓝图实现子域名、访问静态文件
    vim中编辑了代码 但是提示can not write的解决办法和代码对齐办法
    makefile笔记
  • 原文地址:https://www.cnblogs.com/wangshengjun/p/cf22A.html
Copyright © 2011-2022 走看看