原题:http://acm.hdu.edu.cn/showproblem.php?pid=2561
思路:
不明白把这个题放在最后是什么意思,水得很,sort一次直接输出第二位就行了。注意sort对数组操作时默认是从0开始的(貌似可以设置,左边参数可以弄成a+1,这里比较懒)
源代码:
#include <cstdio> #include <algorithm> using namespace std; int a[11]={}; int n,m=0; int main() { scanf("%d",&n); for (int i=1;i<=n;i++) { scanf("%d",&m); for (int j=0;j<m;j++) scanf("%d",&a[j]); sort(a,a+m); printf("%d\n",a[1]); } }
本文介绍了一个简单的编程题目,通过对输入的整数数组进行排序并输出第二个元素来解决该问题。使用了 C++ 语言实现,并提供了完整的源代码。此题适用于初学者练习排序算法。

被折叠的 条评论
为什么被折叠?



