求問,這個到底是我的問題,還是java的問題?

P1567 统计天数

你把最后一段给忽略了。万一最后s>max呢? 在System.out.println前加上: ```cpp max=max>s?max:s; ```
by t162 @ 2019-01-27 10:24:15


//抱歉,第一次,忘了加注釋 //發現忽略全上升情況,以訂正,提交後樣例全部是紫色的?全部超時的意思嗎? public static void main(String[] args) { int max = 0, s = 0;//max記錄最大連續天數,s記錄目前連續天數 Scanner input = new Scanner(System.in); int n = input.nextInt(); int[] arr = new int[n];//把溫度放在一個數組裏 arr[0] = input.nextInt();//先輸入第一個溫度 for (int i = 1; i < n; i++) { arr[i]=input.nextInt(); if(arr[i]>arr[i-1]) s++;//每一個溫度,都和前一個溫度比較,如果大於,s加一 else { max=max>s?max:s; s=0; }//如果不大於,連續中斷,比較最大連續天數 } max = max > s ? max : s; System.out.println(max+1); input.close(); }
by liuwu55 @ 2019-01-27 10:25:55


@[Bambusoideae](/space/show?uid=106140) 對,剛發現,已加 然後樣例全部紫色,0分/哭
by liuwu55 @ 2019-01-27 10:26:58


@[liuwu55](/space/show?uid=178010) ~~抱歉,我看不懂您的文字~~
by t162 @ 2019-01-27 10:28:37


~~玄学Java,一不小心全RE~~
by t162 @ 2019-01-27 10:30:25


@[liuwu55](/space/show?uid=178010) 1<=N<=10^7,就算Java有垃圾回收机制,可是评测姬内存有限啊,开这么大一个数组,不RE才怪
by t162 @ 2019-01-27 10:33:09


@[Bambusoideae](/space/show?uid=106140) 对的,我刚去百度了一下 我提交了三次,两次内存时间超了 一次全部re 请问这个是我的问题吗?
by liuwu55 @ 2019-01-27 10:34:05


@[Bambusoideae](/space/show?uid=106140) 所以这是java的问题吗/哭 别人也是开这么大的数组啊
by liuwu55 @ 2019-01-27 10:35:10


@[liuwu55](/space/show?uid=178010) ``` import java.util.Scanner; public class Main { public static void main(String[] args) { int max = 0, s = 0; Scanner input = new Scanner(System.in); int n = input.nextInt(); int pre,this; pre = input.nextInt(); for (int i = 1; i < n; i++) { this=input.nextInt(); if(this>pre) s++; else { max=max>s?max:s; s=0; } pre=this; } max=max>s?max:s; System.out.println(max+1); input.close(); } } ```
by t162 @ 2019-01-27 10:35:54


抱歉,刚刚是错的。 ``` import java.util.Scanner; public class Main { public static void main(String[] args) { int max = 0, s = 0; Scanner input = new Scanner(System.in); int n = input.nextInt(); int pre,_this; pre = input.nextInt(); for (int i = 1; i < n; i++) { _this=input.nextInt(); if(_this>pre) s++; else { max=max>s?max:s; s=0; } pre=_this; } max=max>s?max:s; System.out.println(max+1); input.close(); } } ```
by t162 @ 2019-01-27 10:37:10


| 下一页