Guest User

zad1

a guest
Nov 9th, 2019
107
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Dishwasher {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int detergent = Integer.parseInt(scanner.nextLine());
  7. detergent = detergent * 750;
  8. String dishesAndPots = scanner.nextLine();
  9. int sumDishes = 0;
  10. int sumPots = 0;
  11. int trace = 1;
  12. int total = sumDishes + sumPots;
  13. int cleanDishes = 0;
  14. int cleanPots = 0;
  15. boolean isTrue = false;
  16. while (!dishesAndPots.equals("End")) {
  17. int dishesAndPotsValue = Integer.parseInt(dishesAndPots);
  18. if (trace % 3 == 0) {
  19. dishesAndPotsValue = dishesAndPotsValue * 15;
  20. sumPots = dishesAndPotsValue;
  21. trace++;
  22. if (detergent >= sumPots) {
  23. cleanPots += (dishesAndPotsValue / 15);
  24. detergent = detergent - sumPots;
  25. } else {
  26. int howMuchWeManaged = detergent / 15;
  27. cleanPots += howMuchWeManaged;
  28. detergent = detergent - sumPots;
  29. isTrue = true;
  30. }
  31. } else {
  32. dishesAndPotsValue = dishesAndPotsValue * 5;
  33. sumDishes = dishesAndPotsValue;
  34. trace++;
  35. if (detergent >= sumDishes) {
  36. cleanDishes += (dishesAndPotsValue / 5);
  37. detergent = detergent - sumDishes;
  38. } else {
  39. int howMuchWeManaged = detergent / 5;
  40. cleanDishes += howMuchWeManaged;
  41. detergent = detergent - sumDishes;
  42. isTrue = true;
  43. }
  44. }
  45. if (isTrue) {
  46. break;
  47. }
  48. dishesAndPots = scanner.nextLine();
  49. }
  50.  
  51. if (total <= detergent) {
  52. System.out.println("Detergent was enough!");
  53. System.out.printf("%d dishes and %d pots were washed.%n", cleanDishes, cleanPots);
  54. System.out.printf("Leftover detergent %d ml.", detergent - total);
  55. }
  56. if (isTrue) {
  57. System.out.printf("Not enough detergent, %d ml. more necessary!", Math.abs(total - detergent));
  58. }
  59. }
  60. }
RAW Paste Data