Advertisement
damesova

Dec 18 [Mimi] - All

Mar 8th, 2019
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. package OLD_MID_EXAMs_18_12_18;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class _01_ChristmasSpirit {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int quantity = Integer.parseInt(scanner.nextLine());
  10. int days = Integer.parseInt(scanner.nextLine());
  11.  
  12. int ornamentSet = 2;
  13. int treeSkirt = 5;
  14. int treeGarlands = 3;
  15. int treeLights = 15;
  16.  
  17. int costs = 0;
  18. int spirit = 0;
  19.  
  20. for (int i = 1; i <= days; i++) {
  21. if (i % 11 == 0){
  22. quantity += 2;
  23. }
  24.  
  25. if (i % 10 == 0){
  26. spirit -= 20;
  27. costs += (treeSkirt + treeGarlands + treeLights);
  28. if (i == days){
  29. spirit -= 30;
  30. }
  31. }
  32.  
  33. if (i % 5 == 0){
  34. costs += (treeLights * quantity);
  35. spirit += 17;
  36. if (i % 3 == 0){ //допускам, че и 10-я ден влиза в това условие, но не съм сигурна
  37. spirit += 30;
  38. }
  39.  
  40. }
  41.  
  42. if (i % 3 == 0){
  43. costs += ((treeSkirt + treeGarlands) * quantity);
  44. spirit += 13;
  45. }
  46.  
  47. if (i % 2 == 0){
  48. costs += (ornamentSet * quantity);
  49. spirit += 5;
  50. }
  51. }
  52.  
  53. System.out.println("Total cost: " + costs);
  54. System.out.println("Total spirit: " + spirit);
  55.  
  56. }
  57. }
  58.  
  59. ................................
  60.  
  61. package OLD_MID_EXAMs_18_12_18;
  62.  
  63. import java.util.Arrays;
  64. import java.util.List;
  65. import java.util.Scanner;
  66. import java.util.stream.Collectors;
  67.  
  68. public class _02_SantasList {
  69. public static void main(String[] args) {
  70. Scanner scanner = new Scanner(System.in);
  71.  
  72. List<String> kids = Arrays.stream(scanner.nextLine()
  73. .split("&"))
  74. .collect(Collectors.toList());
  75.  
  76. String input = "";
  77. while (!"Finished!".equals(input = scanner.nextLine())) {
  78.  
  79. String[] lineArr = input.split("\\s+");
  80. String command = lineArr[0].trim(); //за всеки случай, да не остане спейс,защото няма да мачне
  81.  
  82. switch (command) {
  83. case "Bad":
  84. if (!kids.contains(lineArr[1])) {
  85. kids.add(0, lineArr[1]);
  86. }
  87. break;
  88. case "Good":
  89. kids.remove(lineArr[1]);
  90. break;
  91. case "Rename":
  92. if (kids.contains(lineArr[1])) {
  93.  
  94. kids.set(kids.indexOf(lineArr[1]), lineArr[2]);
  95. }
  96. break;
  97. case "Rearrange":
  98. if (kids.contains(lineArr[1])) {
  99. kids.remove(lineArr[1]);
  100. kids.add(lineArr[1]);
  101. }
  102. break;
  103. }
  104.  
  105. }
  106.  
  107. System.out.println(kids.toString().replaceAll("[\\[\\]]", ""));
  108. }
  109. }
  110.  
  111. ................................................
  112.  
  113. package OLD_MID_EXAMs_18_12_18;
  114.  
  115. import java.util.ArrayList;
  116. import java.util.Arrays;
  117. import java.util.List;
  118. import java.util.Scanner;
  119. import java.util.stream.Collectors;
  120.  
  121. public class _03_PresentDelivery {
  122. public static void main(String[] args) {
  123. Scanner scanner = new Scanner(System.in);
  124.  
  125. List<Integer> numbers = Arrays.stream(scanner.nextLine()
  126. .split("@"))
  127. .map(Integer::parseInt)
  128. .collect(Collectors.toList());
  129.  
  130. String input = "";
  131. int currentIndex = 0;
  132.  
  133. while (!"Merry Xmas!".equals(input = scanner.nextLine())) {
  134. String[] command = input.split("\\s+");
  135. int steps = Integer.parseInt(command[1].trim());
  136.  
  137. //bounding the currentIndex (position):
  138. if (currentIndex + steps >= numbers.size()) {
  139. currentIndex = (currentIndex + steps) % numbers.size();
  140. } else {
  141. currentIndex += steps;
  142. }
  143.  
  144. if (numbers.get(currentIndex) == 0) {
  145. System.out.printf("House %d will have a Merry Christmas.%n", currentIndex);
  146. } else {
  147. numbers.set(currentIndex, numbers.get(currentIndex)-2);
  148. }
  149.  
  150. }
  151.  
  152. //print that in any case:
  153. System.out.printf("Santa's last position was %d.%n", currentIndex);
  154.  
  155. //to find now many houses've been successfully delivered:
  156. int countHouse = 0;
  157. for (Integer number : numbers) {
  158. if (number == 0){
  159. countHouse++;
  160. }
  161. }
  162.  
  163. if (countHouse == numbers.size()) {
  164. System.out.println("Mission was successful.");
  165. } else {
  166. System.out.printf("Santa has failed %d houses.%n",
  167. numbers.size() - countHouse);
  168. }
  169.  
  170. }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement