Title address: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=94??
Description
Tom has many cigarettes. We hypothesized that he has n cigarettes and smokes them
One by one keeping all the butts. Out of k > 1 butts He can roll a new cigarette.
now, know how many cigarettes can Tom have?
input
First input is a single Line,it's N and stands for there be n testdata.then there be n lines, each line contains Integer numbers giving the values of N and K.
Output
For each line of input, output one integer number on a separate line giving the maximum number of cigarettes that Peter CA N has.
Sample Input
3
4 3
10 3
100 5
Sample Output
5
-124?? Code:? #include <stdio.h>
Calculate how many cigarettes are pumped
N-Current number of cigarette butts
K-k cigarette butts can smoke 1 cigarettes.
static int calcigarettes (int n,int k);
int main ()
{
???? int readlen = 0;
???? scanf ("%d", &readlen);
???? GetChar ();
????
???? while (Readlen > 0)
???? {
????????? int n = 0;
????????? int k = 0;
????????? scanf ("%d%d", &n,&k);
????????? GetChar ();
????????? printf ("%d\n", Calcigarettes (n,k));
?????????
????????? --readlen;
???? }
????
???? return 0;
}
Calculate how many cigarettes are pumped
N-Current number of cigarette butts
K-k cigarette butts can smoke 1 cigarettes.
static int calcigarettes (int n,int k)
{
???? if (n<k | | k<=1)
????????? return n;
???? Already smoked n cigarettes.
???? int result = N;
????
???? Do
???? {
????????? K-cigarettes can be extracted from cigarette butts
????????? int addcigaretcount = n/k;
????????? n = n k + addcigaretcount;
????????? result + = Addcigaretcount;
???? }while (n >= k);//The remainder of the cigarette butts and K, equal also need to be
????
???? return result;
}?? When doing the problem, missed the original smoking cigarette-N In addition to judge the condition is also wrong, missing the equal situation of the judgment?? For a given test data test no problem, has been unable to find the problem where the error, and then learn from the "16-language primer -16-who won the highest scholarship" error to find the wrong experience from the input data, continuous input of the following data? 2 33 34 35 36 37 38 39 3 when Input 9 3 o'clock, find a little count. 1, finally identified the place where the error occurred.
24-Language Primer -24-cigarettes