本文主要是介绍codeforces 580A(Kefa and First Steps) Java,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
出去浪了一段时间,回来继续虐水题!!!
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;/*** 题意:求连续的最长非递减子序列** @author TinyDolphin* 2017/7/2 15:31.*/
public class Main {public static void main(String[] args) throws IOException {StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));int inputN;int beforeNum;int afterNum;int count;int maxCount;while (in.nextToken() != StreamTokenizer.TT_EOF) {inputN = (int) in.nval;in.nextToken();beforeNum = (int) in.nval;maxCount = Integer.MIN_VALUE;count = 1;while (inputN-- != 1) {in.nextToken();afterNum = (int) in.nval;if (beforeNum <= afterNum) {count++;} else {maxCount = maxCount > count ? maxCount : count;count = 1;}beforeNum = afterNum;}//预防只有一个输入数(如:1)和只有一个非递减子序列(如:1,3,4)的情况out.println(maxCount > count ? maxCount : count);}out.flush();}
}
这篇关于codeforces 580A(Kefa and First Steps) Java的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!