close
題目概要:
計算出可以喝多少瓶汽水。e=目前手上的空瓶,f=撿到的空瓶,c=需要幾瓶空瓶換一罐汽水。
解題方向:
1. 可以換的汽水數量=所有空瓶數/c。
2. 手上空瓶=所有空瓶數/c+所有空瓶數%c。
程式碼:
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 uva11689{ | |
public static void main(String args[]){ | |
Scanner sc=new Scanner(System.in); | |
int cases=sc.nextInt(); | |
for(int i=0;i<cases;i++){ | |
int e=sc.nextInt(),f=sc.nextInt(),c=sc.nextInt(); | |
int total=e+f,count=0; | |
while((total/c)!=0){ | |
count=count+total/c; //共喝多少罐汽水 | |
total=total/c+total%c; //手上剩下的瓶子 | |
} | |
//Output | |
System.out.println(count); | |
} | |
} | |
} |
文章標籤
全站熱搜