题解 | #小Q的排序#C++暴力遍历比较解法

小Q的排序

https://www.nowcoder.com/practice/62a677c595fb471e832e4ed4107d3c63

#include <iostream>
#include <vector>
using namespace std;

int main() 
{
    int i=0;
    int n=0;
    cin>>n;
    vector <int> a;
    int minelement=1000000000;
    int maxelement=0;
    for(i=0;i<n;i++)
    {
        int b=0;
        cin>>b;
        minelement=min(minelement,b);
        maxelement=max(maxelement,b);
        a.push_back(b);
    }
    if(a[0]==minelement  ||  a[n-1]==maxelement)
    {
        cout<<1;
    }
    else
    {
        cout<<2;
    }
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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