close
題目概要:
找出總共轉幾度。
解題方向:
就依照題目給的算法去算即可,只不過都順時針轉時,數字會是0,39,38,37...,逆時針轉時數字會是0,1,2,3,4...。
程式碼:
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 uva10550{ | |
public static void main(String args[]){ | |
Scanner sc=new Scanner(System.in); | |
while(sc.hasNext()){ | |
int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),d=sc.nextInt(); | |
if(a==0 && b==0 && c==0 && d==0) break; | |
int degree=1080; //第一步驟、第三步驟所轉的圈數。 | |
degree+=(a>=b)?(a-b)*9:(40+a-b)*9; //第二步驟 | |
degree+=(b<=c)?(c-b)*9:(40+c-b)*9; //第四步驟 | |
degree+=(c>=d)?(c-d)*9:(40+c-d)*9; //第五步驟 | |
//Output | |
System.out.println(degree); | |
} | |
} | |
} |
文章標籤
全站熱搜