close
題目概要:
計算出Peter共抽了多少菸。n=Peter原有的煙,k=多少個菸頭可以換一支菸。
解題方向:
看程式碼比較快!!
程式碼:
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 uva10346{ | |
public static void main(String args[]){ | |
Scanner sc=new Scanner(System.in); | |
while(sc.hasNext()){ | |
int n=sc.nextInt(),k=sc.nextInt(); | |
int count=n; //計算總共抽多少菸 | |
while(n>=k){ | |
count=count+n/k; | |
n=n/k+n%k; | |
} | |
System.out.println(count); | |
} | |
} | |
} | |
文章標籤
全站熱搜