求绝对值最值

新的解题思路,让我学会了又一种循环方式,以及做题不能想复杂!!加油!!

include <bits/stdc++.h>
#include <iostream>  
#include <vector>  
#include <algorithm>
using namespace std;
int main()
{
    int maxx = 0, minn =100;
    int n;
    cin >> n;
    while(n--)
    {
        int x;
        cin >> x;
        if(abs(x) > abs(maxx))
            maxx = x;
        if(abs(x) < abs(minn))
            minn = x;
    }
    cout << minn << &quot; &quot; << maxx << endl;
  return 0;
}
全部评论

相关推荐

挂的真快
投递小鹏汽车等公司10个岗位
点赞 评论 收藏
分享
代码飞升:别用口语,后端就写后端,前端就写前端,最后别光后悔
点赞 评论 收藏
分享
积极的小学生不要香菜:你才沟通多少,没500不要说难
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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