题目描述
1070: 寻找第二小的数
解决
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int numOneLine;
cin >> numOneLine;
static int numOfArray = numOneLine;
int jimu[numOfArray];
int studentNum[numOfArray];
for (int i = 0; i < numOfArray; i++) {
cin >> studentNum[i];
int lass = studentNum[i];
int student[lass];
for (int j = 0; j < lass; j++) {
cin >> student[j];
}
int nummin = student[0];
int numsecond = student[0];
for (int k = 0; k < lass; k++) {
if (nummin > student[k]) {
nummin = student[k];
}
if (numsecond < student[k]) {
numsecond = student[k];
}
}
bool flag = false;
for (int m = 0; m < lass; m++) {
if (numsecond >= student[m]) {
if (student[m] != nummin) {
numsecond = student[m];
flag = true;
}
}
}
if (!flag) {
cout << "NO" << endl;
} else {
cout << numsecond << endl;
}
}
return 0;
}