close
題目概要:
計算出Mario往上跳幾次,往下跳幾次。
解題方向:
比較每個牆壁的大小,左邊的牆壁大於右邊牆壁=往下跳,左邊牆壁小於右邊牆壁=往上跳。
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Java | |
import java.util.Scanner; | |
class uva11764{ | |
public static void main(String args[]){ | |
Scanner sc=new Scanner(System.in); | |
int total=sc.nextInt(); | |
for(int i=0;i<total;i++){ | |
int N=sc.nextInt(); | |
int wall[]=new int[N]; | |
for(int j=0;j<N;j++){ | |
wall[j]=sc.nextInt(); | |
} | |
int highJ=0; | |
int lowJ=0; | |
for(int j=0;j<N-1;j++){ | |
if(wall[j]<wall[j+1]) highJ++; | |
if(wall[j]>wall[j+1]) lowJ++; | |
} | |
System.out.println("Case "+(i+1)+": "+highJ+" "+lowJ); | |
} | |
} | |
} |
文章標籤
全站熱搜