0分求救!!!!

B4066 [GESP202412 三级] 数字替换

wuyixuan314 @ 2025-01-11 12:56:15

B4066

0分求AC代码 我的代码:

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{int ma=1e9,mi=-1e9;
    int n,k;
    int num[100001];
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>num[i];
        ma=max(num[i],ma);
        mi=min(num[i],mi);
    }
    for(int i=0;i<n;i++)
    {
        if(num[i]<k)
        {
            num[i]=ma;
        }else if(num[i]>k)
        {
            num[i]=mi;
        }
    }
    for(int i=0;i<n;i++)
    {
        cout<<num[i]<<" ";
    }
}

看似没问题却全WA,这是为什么呢???


by pjh0625 @ 2025-01-11 13:58:33

@wuyixuan314

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, nums[10000000], k;
    cin >> n >> k;
    int x, y; 
    for(int i = 0 ; i < n ; i ++){
        cin >> nums[i];
        x = max(nums[i], x);
        y = min(nums[i], y);
    }

    for(int i = 0 ; i < n ;i ++){
        if(nums[i] < k) {
            nums[i] = y;
        } else if (nums[i] > k){
            nums[i] = x;
        }
        cout << nums[i] << " ";
    }
    return 0;
}

by wuyixuan314 @ 2025-01-11 18:31:45

@pjh0625

感谢,已AC


|