http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=2651
這題要注意單位換算然後迴圈進入先扣除往上爬是否小於等於0再加上往下滑,只要小於0就跳出迴圈了
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
String str1[]=scn.nextLine().split(" "),str2[]=scn.nextLine().split(" "),str3[]=scn.nextLine().split(" ");
double n=0,r=0,d=0;
int count=0;
if(str1[1].equals("m"))
n=Double.parseDouble(str1[0])*100;
else
n=Double.parseDouble(str1[0]);
if(str2[1].equals("m"))
r=Double.parseDouble(str2[0])*100;
else
r=Double.parseDouble(str2[0]);
if(str3[1].equals("m"))
d=Double.parseDouble(str3[0])*100;
else
d=Double.parseDouble(str3[0]);
while(true){
n-=r;
if(n<=0)
break;
n+=d;
count++;
}
System.out.println(count+1);
}
/*
題目:[C_MM102-易] 小蝸牛
作者:1010
時間:西元 2016 年 8 月 */
}