NC14322. Is Sorted
描述
输入描述
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".
示例1
输入:
3 3 1 2 3 3 3 2 1 4 1 1 2 3
输出:
Yes No No
C++14(g++5.4) 解法, 执行用时: 3ms, 内存消耗: 356K, 提交时间: 2018-05-15 00:54:09
#include <bits/stdc++.h> using namespace std; int t; int n; int a[110]; int main(void) { cin>>t; while (t--) { cin>>n; for (int i=1;i<=n;++i) cin>>a[i]; cout<<((is_sorted(a+1,a+1+n) && unique(a+1,a+1+n)==a+1+n)?"Yes":"No")<<endl; } return 0; }
C++ 解法, 执行用时: 4ms, 内存消耗: 352K, 提交时间: 2021-06-30 15:37:19
#include <stdio.h> int main () { int n,m,i,k,a,b; scanf("%d",&n); while(n--) { scanf("%d%d",&m,&a); for(k=1,i=2;i<=m;i++) { scanf("%d",&b); if(b<=a) k=0; a=b; } if(k) printf("Yes\n"); else printf("No\n"); } return 0; }
C(clang 3.9) 解法, 执行用时: 1ms, 内存消耗: 376K, 提交时间: 2020-07-31 20:34:07
# include <stdio.h> int main(){ int n,m,j; scanf("%d",&n); while(n--){ scanf("%d\n",&m); int i=-1,k=1; while(m--){ scanf("%d",&j); if(i>=j) k=0; i=j; } printf(k?"Yes\n":"No\n"); } return 0; }
Python3(3.5.2) 解法, 执行用时: 27ms, 内存消耗: 3424K, 提交时间: 2018-12-18 00:58:24
n=int(input()) for i in range(n): Null=input() a=list(map(int,input().split())) if all(x<y for x,y in zip(a,a[1:])): print("Yes") else: print("No")