11689 - Soda Surpler

Tim is an absolutely obsessive soda drinker, he simply cannot get enough. Most annoyingly though, he almost never has any money, so his only obvious legal way to obtain more soda is to take the money he gets when he recycles empty soda bottles to buy new ones. In addition to the empty bottles resulting from his own consumption he sometimes find empty bottles in the street. One day he was extra thirsty, so he actually drank sodas until he couldn't afford a new one.

Input

The first line of the input file contains an integer N (N<15) which denotes the total number of test cases. The description of each test case is given below:

Three non-negative integers e,f,c, where e<1000 equals the number of empty soda bottles in Tim's possession at the start of the day, f<1000 the number of empty soda bottles found during the day, and 1<c<2000 the number of empty bottles required to buy a new soda.

Output

For each test case print how many sodas did Tim drink on his extra thirsty day? Look at the sample output for details.

Sample Input

2
9 0 3
5 5 2

Sample Output

4
9
解题思路:这题就是给定瓶子数,捡到的瓶子数和多少个瓶子可以换一瓶饮料,求一共可以喝几瓶,
先计算瓶子总数,然后按比例换成饮料,喝完再换,直到瓶子数小于换饮料比例
#include<stdio.h>
int main()
{int n,e,f,c,sum,a,flag;
scanf("%d",&n);
while(n--){sum=0;
           scanf("%d%d%d",&e,&f,&c);
           a=e+f;
           while(a){flag=a/c;
                    sum+=a/c;
                    a=flag+a%c;
                    if(a<c-1)break;
                    else if(a<=c-1)break;
                    }
           printf("%d\n",sum);
           }
return 0;
}

 

posted on 2013-02-22 19:03  喂喂还债啦  阅读(486)  评论(0编辑  收藏  举报