- 题目来源:2561
- 题意分析:找出一堆数中第二小的整数,和题目说的一样
- 我的思路:冒泡或者sort()一下就ok了,但是我因为没看到多个测试用例还是吃了几记WA 。 ┭┮﹏┭┮
- 完整代码:
代码语言:javascript
复制#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("%dn", a[1]);
}
}
return 0;
}
代码语言:javascript
复制#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;
}