Advertisement
Guest User

Manjur Khan

a guest
Oct 10th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. //MK
  2. import java.util.Scanner;
  3. public class NumberOfChocolate {
  4.     public static void main(String[] args) {
  5.         Scanner input = new Scanner(System.in);
  6.         int n = input.nextInt(), m = input.nextInt(),
  7.                 p = input.nextInt(), wrap;
  8.         if (n < 0 || n > 1000) { //price per chocolate
  9.             System.out.println("Please enter number between 0 and 1000");
  10.             n = input.nextInt();
  11.         }
  12.         if (m < n || m > 1001) { // numbers of wrappers for exchange
  13.             System.out.println("Please enter number between " + n + " and 1001");
  14.             m = input.nextInt();
  15.         }
  16.         if (p < 0 || p > 1000) { // total number of friends
  17.             System.out.println("Please enter number between 0 and 1000");
  18.             p = input.nextInt();
  19.         }
  20.        
  21.         int[] q = new int[p];
  22.         int[] chocolates = new int[p]; //amount of money each friend have
  23.        
  24.         for(int i = 0; i < q.length; i++) {
  25.             q[i] = input.nextInt();
  26.             if (q[i] < 0 || q[i] > 1000000) { // money friend [i] have
  27.                 System.out.println("Please enter number between 0 and 1,000,000");
  28.                 q[i] = input.nextInt();
  29.             }
  30.         }
  31.        
  32.         for(int i = 0; i < q.length; i++) {
  33.             chocolates[i] = q[i]/n;
  34.             wrap = chocolates[i] / m;
  35.             while(wrap != 0) {
  36.                 chocolates[i] += wrap;
  37.                 if(((wrap % m) + (wrap / m)) >= m && ((wrap % m) + (wrap / m)) < 2 * m) {
  38.                     chocolates[i] += 1;
  39.                 }
  40.                 wrap = wrap / m;
  41.                
  42.             }
  43.             System.out.println(chocolates[i]);
  44.         }
  45.        
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement