hesh 2
// Следните класи веќе се импортирани, не е дозволено копирање на класи овде, директно користејте ги како кога се достапни во други локални фајлови:
// The following classes are already imported, copying classes here is not allowed, use them directly as when they are available in other local files:
// CBHT, OBHT, MapEntry, SLLNode веќе се импортирани
// CBHT, OBHT, MapEntry, SLLNode are already imported
// Следните класи веќе се импортирани, не е дозволено копирање на класи овде, директно користејте ги како кога се достапни во други локални фајлови:
// The following classes are already imported, copying classes here is not allowed, use them directly as when they are available in other local files:
// CBHT, OBHT, MapEntry, SLLNode веќе се импортирани
// CBHT, OBHT, MapEntry, SLLNode are already imported
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;
import java.util.PriorityQueue;
// Овде креирајте ги помошните класи за клуч и вредност
// Исполнете ги барањата од текстот за toString методите
// Дополнително осигурете се дека вашата клуч класа ќе ги имплементира потребните
// hashCode и equals методи
// Create the helper classes for key and value here
// Fulfill the requirements from the text for the toString methods
// Additionally, make sure that your key class will implement the required
// hashCode and equals methods
class Entry implements Comparable<Entry> {
String name;
String surname;
int budget;
String ip_adr;
String time;
String city;
int price;
public Entry(String name, String surname, int budget, String ip_adr, String time, String city, int price){
this.name = name;
this.surname = surname;
this.budget = budget;
this.ip_adr = ip_adr;
this.time = time;
this.city = city;
this.price = price;
}
public String toString(){
return name + " "+surname + " with salary "+budget +" from address "+ip_adr+" who spent "+price+"\n";
}
public boolean hasBudget(){
return price<=budget;
}
@Override
public int compareTo(Entry o) {
return 0;
}
}
public class Main {
public static void main(String[] args) {
Comparator<Entry> comparator = (Entry e1, Entry e2) -> {
return Integer.compare(e2.price, e1.price);
};
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
CBHT<String, ArrayList<Entry>> map = new CBHT<>(n);
for(int i = 0; i<n; i++){
String name = scn.next();
String surname = scn.next();
int budget = Integer.parseInt(scn.next());
String ip_adr = scn.next();
String time = scn.next();
String city = scn.next();
int price = Integer.parseInt(scn.next());
Entry entry = new Entry(name, surname, budget, ip_adr, time, city, price);
if(!entry.hasBudget())continue;
SLLNode<MapEntry<String, ArrayList<Entry>>> existing = map.search(city);
if(existing != null){
existing.element.value.add(entry);
}
else{
ArrayList<Entry> arr = new ArrayList<>();
arr.add(entry);
map.insert(city,arr);
}
}
int m = scn.nextInt();
for(int i = 0; i<m; i++){
String name = scn.next();
String surname = scn.next();
int budget = Integer.parseInt(scn.next());
String ip_adr = scn.next();
String time = scn.next();
String city = scn.next();
int price = Integer.parseInt(scn.next());
ArrayList<Entry> list = map.search(city).element.value;
Entry max = list.get(0);
int count= 0;
for(Entry ent : list){
if(ent.price>max.price) max = ent;
count++;
}
System.out.println("City: "+city+" has the following number of customers:");
System.out.println(count);
System.out.println("The user who spent the most purchasing for that city is:");
System.out.println(max.toString());
}
}
}
Editor is loading...
Leave a Comment