题解(A30711.不与最大数相同的数)
2024-11-16 13:34:50
发布于:四川
3阅读
0回复
0点赞
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> nums(N);
for (int i = 0; i < N; ++i) {
cin >> nums[i];
}
int max_num = nums[0];
for (int i = 1; i < N; ++i) {
if (nums[i] > max_num) {
max_num = nums[i];
}
}
int sum = 0;
for (int i = 0; i < N; ++i) {
if (nums[i] != max_num) {
sum += nums[i];
}
}
cout << sum << endl;
return 0;
}
全部评论 1
以及
#include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> nums(N); for (int i = 0; i < N; ++i) { cin >> nums[i]; } int max_num = nums[0]; int total_sum = nums[0]; int max_count = 1; for (int i = 1; i < N; ++i) { if (nums[i] > max_num) { max_num = nums[i]; max_count = 1; } else if (nums[i] == max_num) { max_count++; } total_sum += nums[i]; } int sum = total_sum - max_num * max_count; cout << sum << endl; return 0; }
以及3
#include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> nums(N); for (int i = 0; i < N; ++i) { cin >> nums[i]; } int max_num = nums[0]; int total_sum = nums[0]; int max_count = 1; for (int i = 1; i < N; ++i) { if (nums[i] > max_num) { max_num = nums[i]; max_count = 1; } else if (nums[i] == max_num) { max_count++; } total_sum += nums[i]; } int sum = total_sum - max_num * max_count; cout << sum << endl; return 0; }
1周前 来自 四川
0
有帮助,赞一个