zoukankan      html  css  js  c++  java
  • HDU.2561 第二小整数(water)

    • 题目来源:2561
    • 题意分析:找出一堆数中第二小的整数,和题目说的一样
    • 我的思路:冒泡或者sort()一下就ok了,但是我因为没看到多个测试用例还是吃了几记WA 。 ┭┮﹏┭┮
    • 完整代码:
    #include<stdio.h>
    int main(void)
    {
        int c;
        while (scanf("%d", &c) != EOF)
        {
            while (c-- > 0)
            {
                int n, a[10], temp;
                int i, j;
                scanf("%d", &n);
                for (i = 0; i < n; i++)
                    scanf("%d", &a[i]);
                for (i = 0; i < n - 1; i++)
                {
                    for (j = 0; j < n - 1 - i; j++)
                    {
                        if (a[j] > a[j + 1])
                        {
                            temp = a[j];
                            a[j] = a[j + 1];
                            a[j + 1] = temp;
                        }
                    }
                }
                printf("%d
    ", a[1]);
            }
        }
        return 0;
    }
    • C++:
    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    int main()
    {
        int c;
        int n, a[11], i;
        while (cin>>c)
        {
            while (c-- > 0)
            {
                cin >> n;
                for (i = 0; i < n; i++)
                    cin >> a[i];
                sort(a, a + n);
                cout << a[1] << endl;
            }
        }
        return 0;
    }
  • 相关阅读:
    ShellExecuteEx 函数说明
    npm
    Byte和char
    如何高效阅读一个项目
    C++中慎用malloc
    #ifdef
    string
    C++与C混合编译
    git@github.com: Permission denied (publickey).
    connect to host github.com port 22: Connection refused
  • 原文地址:https://www.cnblogs.com/FlyerBird/p/9052571.html
Copyright © 2011-2022 走看看