一维数组练习

C.一维数组练习
Time Limit: 1000 MS Memory Limit: 32768 K
Total Submit: 54 (22 users) Total Accepted: 17 (17 users) Special Judge: No
Description
输入一个由n个整数组成的序列,其中序列中任意连续三个整数都互不相同。求该序列中所有递增子序列的个数,并要求分别输出。
Input

先是这组数的个数n,然后是n个整数。

Output

递增序列个数

然后是每个递增序列一行,每行中每个数之间用一个空格分隔。

Sample Input
10
1 10 8 5 9 3 2 6 7 4
Sample Output
3
1 10
5 9
2 6 7




import java.util.*;
public class Main {


public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
while(input.hasNext())
{
int n;
n = input.nextInt();
int s[];
int qwe = 0;
s = new int[n+1];
for(int i=0; i<n; i++)
{
s[i] = input.nextInt();
}
int temp = 0;
int m = 1,w = 0;
for(int i=0; i<n; i++)
{
if(s[i]<s[i+1])
{
m++;
}
else if(s[i]>s[i+1])
{
if(m>=2)
{
m = 1;
w++;
}
else
{
continue;
}
}
}
System.out.printf("%d\n",w);

qwe = 1;
m = 1;
for(int i=0; i<n; i++)
{
if(s[i]<s[i+1])
{
m++;
System.out.printf("%d ",s[i]);
}
else if(s[i]>s[i+1])
{
if(m>=2)
{
System.out.printf("%d\n",s[i]);
m = 1;
}
else
{
continue;
}
}
}

}
}
}



猜你喜欢

转载自blog.csdn.net/wonder__/article/details/79795083