全部评论 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
首页