1 条题解
-
0
#include <iostream> #include <vector> #include <limits> using namespace std; int main() { int n; cin >> n; vector<int> sequence(n); for (int i = 0; i < n; ++i) { cin >> sequence[i]; } int max_value = numeric_limits<int>::min(); int second_max_value = numeric_limits<int>::min(); int max_count = 0; // Find the maximum value and second maximum value for (int num : sequence) { if (num > max_value) { second_max_value = max_value; max_value = num; max_count = 1; } else if (num == max_value) { max_count++; } else if (num > second_max_value) { second_max_value = num; } } // If max_value appears only once, output the second_max_value if (max_count == 1) { cout << second_max_value << endl; } else { cout << max_count << endl; } return 0; }
- 1
信息
- ID
- 1139
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 6
- 标签
- (无)
- 递交数
- 97
- 已通过
- 28
- 上传者