题解 | #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;
}


全部评论

相关推荐

喜欢走神的孤勇者练习时长两年半:爱华,信华,等华,黑华
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务