First, solve the problem. Then, write the code. ” - John Johnson

It's not at all important to get it right the first time. It's vitally important to get it right the last time. ” - Andrew Hunt and David Thomas

Wednesday, July 16, 2014

Peter's Smokes.

Author : Jisan
Programming language : Java
Difficulty : Easy
Status : Accepted
Problem number : UVA-10346
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1287

Code:

import java.util.Scanner;

public class Uva_10346 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = 0, k = 0, ans, butt = 0;
        while (in.hasNext()) {
            n = ans = butt = in.nextInt();
            k = in.nextInt();
            while ((n =butt/k) > 0) {
                ans+= n;
                butt = butt%k + n;
            }
            System.out.println(ans);
        }

    }
}

No comments:

Post a Comment