Advertisement
lameski

Untitled

Mar 21st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Nikola2 {
  4.  
  5. public static void main(String[] args) {
  6. Scanner in = new Scanner(System.in);
  7. int newTotal = 0;
  8. int [] coins = new int[3];
  9. int [] values = new int[3];
  10. values[0] = 1;
  11. values[1] = 2;
  12. values[2] = 5;
  13. for(int i=0; i<3; i++)
  14. coins[i] = in.nextInt();
  15. int p = in.nextInt();
  16.  
  17. for(int i=2; i>=0; i--)
  18. {
  19. while(p>0)
  20. {
  21. p-=values[i];
  22. coins[i]--;
  23. if(p<0)
  24. {
  25. p+=values[i];
  26. coins[i]++;
  27. break;
  28. }
  29. else if(coins[i]==0 || p==0)
  30. {
  31. break;
  32. }
  33. }
  34. newTotal+=coins[i];
  35. }
  36. System.out.println(newTotal);
  37.  
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement