-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathziplaw.java
More file actions
50 lines (35 loc) · 1018 Bytes
/
Copy pathziplaw.java
File metadata and controls
50 lines (35 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/** Name:- Gautham Karkala
email:- gauthamk@andrew.cmu.edu*/
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Scanner;
public class ziplaw {
public static void main(String[] args) {
Scanner keyword = new Scanner(System.in);
System.out.println("Enter the values");
int num_songs = keyword.nextInt();
int selection = keyword.nextInt();
int q[] = new int[num_songs];
HashMap<String,Integer> map = new HashMap<String,Integer>();
for(int i=0;i<num_songs;i++)
{
int value = keyword.nextInt();
String name = keyword.next();
int quality = value*(i+1);
map.put(name, quality);
q[i] = quality;
}
Arrays.sort(q);
for(int i=num_songs-1;i>=(num_songs-selection);i--)
{
for (Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue().equals(q[i])) {
System.out.println(entry.getKey());
break;
}
}
}
keyword.close();
}
}