tryhardyoninfinityhz

Untitled

Feb 7th, 2022
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. public class milkmeasure {
  4. static class cow{
  5. String name;
  6. int milk;
  7. int day;
  8. int difference;
  9. }
  10. // each input contains this
  11. static class comp implements Comparator <cow>{
  12. public int compare(cow c1, cow c2) {
  13. if(c1.day < c2.day) {
  14. return -1;
  15. }
  16. else {
  17. return 1;
  18. }
  19. }
  20. }
  21. //sort by days in incremeneting order
  22. public static void main(String[] args) throws IOException{
  23. Scanner scan = new Scanner(new File("measurement.in"));
  24. PrintWriter fout = new PrintWriter(new File("measurement.out"));
  25. int n = scan.nextInt();
  26. int counter = 0;
  27. cow arr[] = new cow[n];
  28. for(int i = 0; i < n; i++) {
  29. arr[i] = new cow();
  30. arr[i].day = scan.nextInt();
  31. arr[i].name = scan.next();
  32. arr[i].difference = scan.nextInt();
  33. }
  34. //input
  35. Arrays.sort(arr, new comp());
  36. //sort cows by days added
  37. cow names[] = new cow[3];
  38. for(int i= 0 ;i < 3; i++) {
  39. names[i] = new cow();
  40. names[i].milk = 0;
  41. }
  42. names[0].name = "Bessie";
  43. names[1].name = "Mildred";
  44. names[2].name = "Elsie";
  45. // I use the cow class to just make it for Bessie, Mildred, and Elsie.
  46. // This way, we can store it easily
  47. String previousWinner = "";
  48. for(int i = 0; i < n; i++) {
  49. String winner = "";
  50. if(arr[i].name.equals("Bessie")) {
  51. names[0].milk += arr[i].difference;
  52. }
  53. // add all everything from input into each cows' profile
  54. else if(arr[i].name.equals("Mildred")){
  55. names[1].milk += arr[i].difference;
  56. }
  57. else {
  58. names[2].milk += arr[i].difference;
  59. }
  60. Arrays.sort(names, new comp());
  61. if(names[0].milk > names[1].milk && names[0].milk > names[2].milk) {
  62. winner = "Bessie";
  63. // Bessie wins
  64. }
  65. else if(names[1].milk > names[0].milk && names[1].milk > names[2].milk) {
  66. winner = "Mildred";
  67. //Mildred wins
  68. }
  69. else if(names[2].milk > names[0].milk && names[2].milk > names[1].milk) {
  70. winner = "Elsie";
  71. //Elsie wins
  72. }
  73. else if(names[0].milk == names[1].milk && names[0].milk > names[2].milk) {
  74. winner = "Bessie Mildred";
  75. //Bessie and Mildred tied for win
  76. }
  77. else if(names[0].milk == names[2].milk && names[0].milk > names[1].milk) {
  78. winner = "Bessie Elsie";
  79. //Bessie and Elsie are tied for win
  80. }
  81. else if(names[1].milk == names[2].milk && names[2].milk > names[0].milk) {
  82. winner = "Mildred Elsie";
  83. //Mildred and Elsie are tied for win
  84. }
  85. else {
  86. winner = "Bessie Mildred Elsie";
  87. // they are all tied for the win
  88. }
  89. if(!winner.equals(previousWinner)) {
  90. counter++;
  91. // if the previous winner isn't equal to the winner, the scoreboard changes
  92. }
  93. previousWinner = winner;
  94. //replace previousWinner with the winner;
  95. }
  96. fout.println(counter);
  97. //output.
  98. fout.close();
  99. }
  100. }
  101.  
Advertisement
Add Comment
Please, Sign In to add comment