zoukankan      html  css  js  c++  java
  • Java实现 洛谷 P1567 统计天数

    在这里插入图片描述

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.util.StringTokenizer;
    
    public class Main {
        private static CustomizedReader cin;
    
        public static void main(String args[]) throws Exception {
            cin = new CustomizedReader(System.in);
            int n = cin.nextInt();
            if(n<=0 || n>Math.pow(10, 7)) {
                return;
            }
            int historyRecord = 0;
            int newRecord = 0;
            int startTemprature = -1;
            int MAX = (int) Math.pow(10, 9);
            for (int i = 0; i < n; i++) {
                int t = cin.nextInt();
                if(t>=0&&t<=MAX) {
                    if(t > startTemprature) {
                        newRecord++;
                        startTemprature = t;
                    }else {
                        if(newRecord > historyRecord) {
                            historyRecord = newRecord;
                        }
                        newRecord = 1;
                        startTemprature = t;
                    }
                }
            }
            if(newRecord > historyRecord) {
                historyRecord = newRecord;
            }
            System.out.println(historyRecord);
        }
    }
    
    class CustomizedReader {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer;
        
        CustomizedReader(InputStream source){
            reader = new BufferedReader(new InputStreamReader(source) );
            tokenizer = new StringTokenizer("");
        }
        
        public String next() {
            while ( ! tokenizer.hasMoreTokens() ) {
                //TODO add check for eof if necessary
                try {
                    tokenizer = new StringTokenizer(reader.readLine() );
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return tokenizer.nextToken();
            
        }
        
        public int nextInt() {
            return Integer.parseInt(next());
        }
    
        public double nextDouble() {
            return Double.parseDouble(next());
        }
        
        public double nextLong() {
            return Long.parseLong(next());
        }
        
        public double nextFloat() {
            return Float.parseFloat(next());
        }
        
    }    
    
    
  • 相关阅读:
    在ASP.NET中使用FusionCharts图表
    IE 输入baidu就死掉
    以WebServices方式上传图片
    GUID System.Guid .
    记录一个静态类的静态属性
    [转]通用分页存储过程
    如何解决“呈现控件时出错”的问题
    C#中调用SQL存储过程(带输入输出参数的例子)
    Rose实例:构造银行业务模型[转]
    Mylove net 我们手里的金钱只是保持自由的一种工具!卢梭
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13076220.html
Copyright © 2011-2022 走看看