• 求第N数大问题


    问题:

    Input
    The first line of input contains a single integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. Each data set consists of a single line containing the data set number, followed by a space, followed by 10 space separated decimal integers whose values are between 1 and 1000 inclusive.

    Output
    For each data set, generate one line of output with the following values: The data set number as a decimal integer, a space, and the 3rd largest value of the corresponding 10 integers.

    Sample Input
    4
    1 1 2 3 4 5 6 7 8 9 1000
    2 338 304 619 95 343 496 489 116 98 127
    3 931 240 986 894 826 640 965 833 136 138
    4 940 955 364 188 133 254 501 122 768 408

    Sample Output
    1 8
    2 489
    3 931
    4 768

    回答:题意输出10个数,求里面第3大数问题。如"1 2 3 4 5 6 7 8 9 1000"里面数值排第三是8。

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    int main()
    {
        int T;
        for(scanf("%d",&T);T;T--)
        {
            int ca,a[12];
            scanf("%d",&ca);
            for(int i=0;i<10;i++)
                scanf("%d",a+i);
            sort(a,a+10);
            printf("%d %d ",ca,a[7]);
        }
        return 0;
    }

  • 相关阅读:
    js 遇到问题
    table 排序 添加 删除 等操作
    json对象
    .style, .getComputedStyle(),.currentStyle区别
    3个div 宽度移入移出时变化
    运动 js
    OWASP Top 10之文件上传漏洞简析(二)
    owasp top10 之文件上传漏洞简析
    前台实现ajax 需注意的地方
    apache-Rewrite重写规则配置
  • 原文地址:https://www.cnblogs.com/benchao/p/4523773.html
Copyright © 2020-2023  润新知