题解 | #获取数组最值#

获取数组最值

https://www.nowcoder.com/practice/53d110f6cdd14f21af285698f975b59c

 #include <iostream>
using namespace std;

int main() {

    int arr[6] = { 0 };
    int len = sizeof(arr) / sizeof(int);
    
    for (int i = 0; i < len; i++) {
        cin >> arr[i];
    }

    // write your code here......
    int min = 0;
    int max = 0;
    int brr[6];
    copy(arr,arr+5,brr);
    for (int j=0; j<len-1;j++){
        
    if(brr[j] <= brr[j+1])
    {
        min = brr[j] ;
        brr[j+1] = brr[j];    
    }
    else {
        min = brr[j+1];
    }

    if(arr[j] >= arr[j+1])
    {
        max = arr[j] ;
        arr[j+1] = arr[j];    
    }
    else {
        max = arr[j+1];
    }
    
    }
    cout << min <<" "<< max << endl;
    return 0;
}

全部评论

相关推荐

点赞 评论 收藏
分享
06-25 16:25
梧州学院 Java
愿汐_:项目介绍那么长,然而你做了啥就一句话?
点赞 评论 收藏
分享
07-28 00:10
已编辑
门头沟学院 算法工程师
码农索隆:这哥们库库在我帖子下评论
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务