题解 | #Is Sorted#

Is Sorted

https://ac.nowcoder.com/acm/problem/14322

题目描述

A sequence contains n integers, can you make a judgment of whether the sequence is strictly increasing.

输入描述:

There are multiple test cases. The first line is an positive integer indicating the number of test cases.
For each test case:
Line 1. A positive integer n, standing for the number of elements in the sequence.
Line 2. This line contains n integers, a1, a2, ..., an(2<=n<=100, 0<=ai<=1000) separated by space.

输出描述:

For each test case, output one line. If the sequence is strictly increasing, print "Yes", else print "No".

数组中,若出现“后一个数大于等于前一个数”,则该数组非递增
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int t;
    cin>>t;
    int n,sum;
    while(t--)
    {
        vector<int> a;
        bool flag=true;
        cin>>n;
        for(int i=0;i<n;i++)
        {
            cin>>sum;
            a.push_back(sum);
        }
        for(int i=0;i<n-1;i++)
        {
            if(a[i]>=a[i+1]) 
            {
                flag=false;
                cout<<"No"<<endl;
                break;
            }
        }
        if(flag) cout<<"Yes"<<endl;
    }
    return 0;
}


全部评论

相关推荐

jack_miller:我给我们导员说我不在这里转正,可能没三方签了。导员说没事学校催的时候帮我想办法应付一下
点赞 评论 收藏
分享
已老实求offer😫:有点像徐坤(没有冒犯的意思哈)
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务