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());
        }
        
    }    
    
    
  • 相关阅读:
    计算GPS WGS_84 两点的距离
    极路由4_开ssh_刷breed
    aes-256-gcm_python3_php7_golang
    nginx_非标准端口_同端口_http_自动跳转_https
    配置sshd_除了特定ip外_仅密钥登录
    使用scp命令实现服务器之间文件传输
    Java防止重复提
    mysql使用SUBSTRING_INDEX截取部分字符串
    SEO大杀器rendertron安装
    PIC16 bootloader之I2C bootloader
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13076741.html
Copyright © 2011-2022 走看看