Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- public class CoronaRiskFactor {
- static class Patient {
- private String prezime;
- private String opshtina;
- private String pozitiven;
- public Patient(String prezime, String opshtina, String pozitiven) {
- this.prezime = prezime;
- this.opshtina = opshtina;
- this.pozitiven = pozitiven;
- }
- public String getPrezime() {
- return prezime;
- }
- public void setPrezime(String prezime) {
- this.prezime = prezime;
- }
- public String getOpshtina() {
- return opshtina;
- }
- public void setOpshtina(String opshtina) {
- this.opshtina = opshtina;
- }
- public String getPozitiven() {
- return pozitiven;
- }
- public void setPozitiven(String pozitiven) {
- this.pozitiven = pozitiven;
- }
- }
- // public static Map<String, ArrayList<String>> positive = new HashMap<>();
- // public static Map<String, ArrayList<String>> negative = new HashMap<>();
- // static CBHT<String,String> pozitivni = new CBHT<>(6);
- // static CBHT<String,String> negativni = new CBHT<>(6);
- //
- // public static void addValuesPositive(String key, String value) {
- // ArrayList<String> temp = null;
- // if (pozitivni.equals(key)){
- // if (temp == null)
- // temp = new ArrayList<>();
- // temp.add(value);
- // }
- // else {
- // temp = new ArrayList<>();
- // temp.add(value);
- // }
- // pozitivni.insert(key, String.valueOf(temp));
- // }
- //
- // public static void addValuesNegative(String key, String value) {
- // negativni.insert(key, value);
- // }
- public static void main (String[] args) throws IOException {
- BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
- int N = Integer.parseInt(bf.readLine());
- //
- CBHT<String, Integer> negativePatients = new CBHT<String, Integer>(N*2);
- CBHT<String, Integer> positivePatients = new CBHT<String, Integer>(N*2);
- ArrayList<Patient> patients = new ArrayList<Patient>();
- ArrayList<String> opshtini = new ArrayList<String>();
- for(int i = 0; i<N; i++){
- String p []= bf.readLine().split(" ");
- String opstina = p[0];
- if(!opshtini.contains(opstina)){
- opshtini.add(opstina);
- }
- String prezime = p[1];
- String rezultat = p[2];
- Patient patient = new Patient(prezime, opstina, rezultat);
- patients.add(patient);
- }
- for (String s: opshtini){
- int numberPositive = 0;
- int numberNegative = 0;
- for(Patient p: patients){
- if(p.getOpshtina().equals(s)){
- if(p.getPozitiven().equals("pozitiven")){
- numberPositive++;
- } else if(p.getPozitiven().equals("negativen")){
- numberNegative++;
- }
- }
- }
- negativePatients.insert(s, numberNegative);
- positivePatients.insert(s,numberPositive);
- }
- String opstina = bf.readLine();
- // float total = negativePatients.search(opstina).element.value + positivePatients.search(opstina).element.value;
- // //System.out.println(total);
- // //System.out.println(negativePatients.search(opstina).element.value);
- // //System.out.println(positivePatients.search(opstina).element.value);
- // float numbPositive = positivePatients.search(opstina).element.value;
- // float riskFactor = numbPositive / total;
- System.out.println(negativePatients.search(opstina).element.value);
- System.out.println(positivePatients.search(opstina).element.value);
- // System.out.println(String.format("%.2f", riskFactor));
- // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- // int N = Integer.parseInt(br.readLine());
- //
- //
- // for(int i=0;i<N;i++){
- // String mesto_ime_rez = br.readLine();
- // String[] pom = mesto_ime_rez.split(" ");
- // if(pom[2].equals("pozitiven"))
- // addValuesPositive(pom[0],pom[1]);
- // if(pom[2].equals("negativen"))
- // negativni.insert(pom[0],pom[1]);
- // }
- //
- //
- // System.out.println(pozitivni);
- // System.out.println(negativni);
- // while (true) {
- // String line = br.readLine();
- // String parts [] = line.split(" ");
- // SLLNode<MapEntry<String,String>> temp = table.search(parts[0]);
- //
- // if (temp.getElement().value.equals(parts[1])){
- //
- //
- // }
- //
- // if (line.equals("Центар"))
- // break;
- //
- //
- // if (temp == null || !(temp.getElement().value.equals(parts[1])))
- // System.out.println("Nenajaven");
- // else {
- // System.out.println("Najaven");
- // break;
- // }
- //
- // }
- }
- }
- class CBHT<K extends Comparable<K>,E> {
- private SLLNode<MapEntry<K,E>>[] buckets;
- @SuppressWarnings("unchecked")
- public CBHT(int m) {
- buckets = (SLLNode<MapEntry<K,E>>[]) new SLLNode[m];
- }
- private int hash(K key) {
- // Translate key to an index of the array buckets.
- return Math.abs(key.hashCode()) % buckets.length;
- }
- public SLLNode<MapEntry<K,E>> search(K targetKey) {
- // Find which if any node of this CBHT contains an entry whose key is
- // equal
- // to targetKey. Return a link to that node (or null if there is none).
- int b = hash(targetKey);
- SLLNode<MapEntry<K,E>> curr = buckets[b];
- for (; curr != null; curr = curr.succ) {
- if (targetKey.equals(curr.getElement().key)) {
- return curr;
- }
- }
- return null;
- }
- public void insert(K key, E value) {
- MapEntry<K,E> newEntry = new MapEntry<K,E>(key, value);
- int b = hash(key);
- SLLNode<MapEntry<K,E>> curr = buckets[b];
- for (; curr != null; curr = curr.succ) {
- if (key.equals(curr.getElement().key)) {
- curr.setElement(newEntry);
- return;
- }
- }
- buckets[b] = new SLLNode<MapEntry<K,E>>(newEntry, buckets[b]);
- }
- public void delete (K key) {
- // Delete the entry (if any) whose key is equal to key from this CBHT.
- int b = hash(key);
- SLLNode<MapEntry<K,E>> pred = null, curr = buckets[b];
- for (; curr != null; pred = curr, curr = curr.succ) {
- if (key.equals(curr.getElement().key)) {
- if (pred == null)
- buckets[b] = curr.succ;
- else
- pred.succ = curr.succ;
- return;
- }
- }
- }
- public String toString() {
- String temp = "";
- for (int i = 0; i < buckets.length; i++) {
- temp += i + ":";
- for (SLLNode<MapEntry<K,E>> curr = buckets[i]; curr != null; curr = curr.succ) {
- temp += curr.getElement().toString() + " ";
- }
- temp += "\n";
- }
- return temp;
- }
- }
- class MapEntry<K extends Comparable<K>,E> implements Comparable<K> {
- K key;
- E value;
- public MapEntry(K key, E value) {
- this.key = key;
- this.value = value;
- }
- @Override
- public int compareTo(K that) {
- return this.key.compareTo(that);
- }
- @Override
- public String toString () {
- return "<" + key + "," + value + ">";
- }
- }
- class SLLNode<E> {
- protected E element;
- public SLLNode<E> succ;
- public SLLNode(E element, SLLNode<E> succ) {
- this.setElement(element);
- this.succ = succ;
- }
- @Override
- public String toString() {
- return getElement().toString();
- }
- public E getElement() {
- return element;
- }
- public void setElement(E element) {
- this.element = element;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment