Love丶FFC's Blog
小明正在利用股票的波动程度来研究股票。小明拿到了一只股票每天收盘时的价格,他想知道,这只股票连续几天的最大波动值是多少,即在这几天中某天收盘价格与前一天收盘价格之差的绝对值最大是多少。
输入的第一行包含了一个整数n,表示小明拿到的收盘价格的连续天数。第二行包含n个正整数,依次表示每天的收盘价格。
输出一个整数,表示这只股票这n天中的最大波动值。
6
2 5 5 7 3 5
4
第四天和第五天之间的波动最大,波动值为|3-7|=4。
对于所有评测用例,2 ≤ n ≤ 1000。股票每一天的价格为1到10000之间的整数。
1.枚举法
package CCF_CSP; import java.util.Scanner; public class _20160901_100point { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); //拿到的收盘价格的天数 int[] price = new int[n]; //每天的收盘价格 for(int i=0;i<n;i++) { price[i] = scanner.nextInt(); } int maxdistance = Math.abs(price[1]-price[0]); //定义初始最大差距 for(int i=2;i<n;i++) { if(Math.abs(price[i]-price[i-1]) > maxdistance) //存在更大差距 { maxdistance = Math.abs(price[i]-price[i-1]); } } System.out.println(maxdistance); } }
FoorryNox
Monitor Closely 1 propofol and quazepam both increase sedation cialis 20 mg afatinib will increase the level or effect of dabigatran by P glycoprotein MDR1 efflux transporter
Preliaf
Experimental Biology, 2001, 39, 12, 1235 42 comprar levitra espana 24 This large 2 by 2 factorial study randomly assigned 5, 177 patients undergoing nonemergency angiography to receive isotonic sodium bicarbonate vs isotonic saline as well as oral acetylcysteine vs placebo
PAhxgSog
i took a viagra and it didn’t work If you canГў t figure out how to set up a filter on your email program, just put the question into Google that will find the answer for you
Uxdcll
buy tricor 200mg generic tricor pill tricor 160mg generic
Idnjtf
buy cialis pill viagra cost viagra 50mg ca
Aaxfam
acarbose pills micronase order buy fulvicin 250 mg without prescription
Pipmya
minoxytop medication tamsulosin where to buy can you buy ed pills online