Run ID:147955
提交时间:2026-02-09 09:28:00
#include <iostream> using namespace std; int findSecondSmallest(vector<int> numbers) { int smallest = numeric_limits<int>::max(); int secondSmallest = numeric_limits<int>::max(); for (int num : numbers) { if (num < smallest) { secondSmallest = smallest; smallest = num; } else if (num < secondSmallest && num != smallest) { secondSmallest = num; } } if (secondSmallest == numeric_limits<int>::max()) { return -1; } return secondSmallest; } int main() { int C; cin >> C; for (int i = 0; i < C; i++) { int n; cin >> n; vector<int> numbers(n); for (int j = 0; j < n; j++) { cin >> numbers[j]; } int result = findSecondSmallest(numbers); if (result == -1) { cout << "NO" << endl; } else { cout << result << endl; } } return 0; }