Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. public class RadioGaGa{
  2.  
  3. private static Scanner scan = new Scanner(System.in);
  4. private static int n = scan.nextInt();
  5. private static List<Song> songs = new ArrayList<Song>();
  6. private static int time;
  7. private static double weight;
  8. private static int days;
  9. private static int timeS;
  10. private static int D;
  11. private static SongComparator comparator = new SongComparator();
  12.  
  13. private static void populate(){
  14. for(int i = 0; i < n; i++){
  15. String name = scan.next();
  16. int len = scan.nextInt();
  17. double pop = scan.nextDouble();
  18.  
  19. Song song = new Song(name, len, pop);
  20. songs.add(song);
  21. }
  22.  
  23.  
  24.  
  25. Collections.sort(songs, comparator);
  26. time = scan.nextInt();
  27. weight = scan.nextDouble();
  28. days = scan.nextInt();
  29. timeS = time * 60;
  30. }
  31.  
  32.  
  33. private static String day0(){
  34.  
  35. int pLen = 0;
  36. String result = "";
  37. List<Song> zero = new ArrayList<>();
  38.  
  39. for(int i = 0; i < n; i++){
  40. if(pLen + songs.get(i).getLen() < timeS){
  41. pLen = pLen + songs.get(i).getLen();
  42. zero.add(songs.get(i));
  43. }
  44. }
  45.  
  46. for(Song song : zero){
  47. result += " " + song.getName();
  48. }
  49.  
  50. return D + result;
  51. }
  52. private static String dayN(int D){
  53.  
  54. int pLen = 0;
  55. List<Song> playlist = new ArrayList<>();
  56. String result = "";
  57.  
  58. int requests = scan.nextInt();
  59.  
  60. for(int i = 0; i < requests; i++){
  61. String rName = scan.next();
  62. for (Song song : songs) {
  63. if (song.getName().equals(rName)) {
  64. song.setPop(weight, D);
  65. }
  66. }
  67. }
  68. Collections.sort(songs, comparator);
  69.  
  70. for(int i = 0; i < n; i++){
  71. if(pLen + songs.get(i).getLen() < timeS){
  72. pLen = pLen + songs.get(i).getLen();
  73. playlist.add(songs.get(i));
  74. }
  75. }
  76.  
  77. for(Song song : playlist){
  78. result += " " +song.getName();
  79. }
  80.  
  81. return D + result;
  82. }
  83.  
  84. public static void main(String[] args){
  85.  
  86. populate();
  87. System.out.println(day0());
  88.  
  89. for(int i = 1; i <= days; i++){
  90. System.out.println(dayN(i));
  91. }
  92. }
  93. }
  94. public class Song {
  95.  
  96. private String name;
  97. private int len;
  98. private double pop;
  99.  
  100.  
  101. Song(String name, int len, double pop){
  102. this.name = name;
  103. this.len = len;
  104. this.pop = pop;
  105. }
  106.  
  107.  
  108. public int getLen(){
  109. return this.len;
  110. }
  111.  
  112. public String getName(){
  113. return this.name;
  114. }
  115.  
  116. public double getPop(){
  117. return this.pop;
  118. }
  119.  
  120. public void setPop(double pop, int D){
  121. this.pop = pop + pop;
  122. }
  123.  
  124. public String toString(){
  125. return name;
  126. }
  127.  
  128. }
  129. import java.util.Comparator;
  130.  
  131. public class SongComparator implements Comparator<Song> {
  132.  
  133. private enum Order {pop, len}
  134.  
  135. private Order sortingBy = Order.pop;
  136.  
  137. SongComparator(){
  138.  
  139. }
  140.  
  141. public int compare(Song s1, Song s2) {
  142.  
  143. if(s1.getPop() == s2.getPop()){
  144. if(s1.getLen() < s2.getLen()){
  145. return -1;
  146. }else if(s1.getLen() > s2.getLen()){
  147. return 1;
  148. }else{
  149. return 0;
  150. }
  151. }
  152. if(s1.getPop() < s2.getPop()){
  153. return 1;
  154. }else{
  155. return -1;
  156. }
  157. }
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement