13 solutions

  • 1
    @ 2022-1-10 22:22:45

    看懂题意就简单了,以下是不正规写法; 当输入的数为n时,只要保证后面的数顺序减小便成立;

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int a[1005];
    	int n,t,count=1,temp=0,flag=0;
    	cin>>n;
    	for(int i=0;i<n;i++){
    		cin>>t;
    		if(temp==1){
    			a[count]=t;
    			count++;
    		}
    		if(t==n)
    		temp=1;
    	}
    	if(count>1){
    		for(int i=0;i<count-1;i++){
    			if(a[i]<a[i+1]){
    				flag=1;
    				break;
    			}
    		}
    	}
    	if(flag==1)
    	cout<<"NO";
    	else if(flag==0||count==1)
    	cout<<"YES";
    	return 0;
    }

    Information

    ID
    291
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    6
    Tags
    # Submissions
    139
    Accepted
    44
    Uploaded By