Time Limit: 1000 MS Memory Limit: 131072 KB
Total Submission(s): 393 Accepted Submission(s): 233
Description
实现public static boolean isSorted(int[] table)
判断整数数组元素是否已经按升序排序。
Input
一列数,需要判断的数组元素。
Output
如果已经排序输出YES
如果没有排序输出NO
Sample Input
1 2 3 4 5 6
Sample Output
YES
Hint
import java.util.*;
public class Main{
public static void main(String args[]){
Scanner cin = new Scanner(System.in);
int a, b;
b=-1;
while (cin.hasNext()){
a = cin.nextInt();
if(??????????){
????????;
????????????????????;
}
????????????;
}
if(!cin.hasNext())
????????????????????????
}
}
Source
附上AC代码:
#include<bits/stdc++.h>
#define maxn 55
using namespace std;
int a[maxn];
int b[maxn];
int i,n,t,k;
int main()
{
i=0;
while(cin>>n)
{
a[i]=n;
b[i]=n;
i++;
}
t=i;
i=0;
sort(b,b+t);
for(int i=0;i<t;i++)
{
if(a[i] != b[i])
{
k=-1;
}
}
if(k!=-1)
cout<<"YES";
else
cout<<"NO";
return 0;
}