mankanos

Untitled

Feb 8th, 2021
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.34 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.ArrayList;
  5.  
  6.  
  7. public class CoronaRiskFactor {
  8. static class Patient {
  9. private String prezime;
  10. private String opshtina;
  11. private String pozitiven;
  12.  
  13. public Patient(String prezime, String opshtina, String pozitiven) {
  14. this.prezime = prezime;
  15. this.opshtina = opshtina;
  16. this.pozitiven = pozitiven;
  17. }
  18.  
  19. public String getPrezime() {
  20. return prezime;
  21. }
  22.  
  23. public void setPrezime(String prezime) {
  24. this.prezime = prezime;
  25. }
  26.  
  27. public String getOpshtina() {
  28. return opshtina;
  29. }
  30.  
  31. public void setOpshtina(String opshtina) {
  32. this.opshtina = opshtina;
  33. }
  34.  
  35. public String getPozitiven() {
  36. return pozitiven;
  37. }
  38.  
  39. public void setPozitiven(String pozitiven) {
  40. this.pozitiven = pozitiven;
  41. }
  42. }
  43. // public static Map<String, ArrayList<String>> positive = new HashMap<>();
  44. // public static Map<String, ArrayList<String>> negative = new HashMap<>();
  45. // static CBHT<String,String> pozitivni = new CBHT<>(6);
  46. // static CBHT<String,String> negativni = new CBHT<>(6);
  47. //
  48. // public static void addValuesPositive(String key, String value) {
  49. // ArrayList<String> temp = null;
  50. // if (pozitivni.equals(key)){
  51. // if (temp == null)
  52. // temp = new ArrayList<>();
  53. // temp.add(value);
  54. // }
  55. // else {
  56. // temp = new ArrayList<>();
  57. // temp.add(value);
  58. // }
  59. // pozitivni.insert(key, String.valueOf(temp));
  60. // }
  61. //
  62. // public static void addValuesNegative(String key, String value) {
  63. // negativni.insert(key, value);
  64. // }
  65. public static void main (String[] args) throws IOException {
  66. BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  67. int N = Integer.parseInt(bf.readLine());
  68. //
  69. CBHT<String, Integer> negativePatients = new CBHT<String, Integer>(N*2);
  70. CBHT<String, Integer> positivePatients = new CBHT<String, Integer>(N*2);
  71. ArrayList<Patient> patients = new ArrayList<Patient>();
  72. ArrayList<String> opshtini = new ArrayList<String>();
  73.  
  74. for(int i = 0; i<N; i++){
  75. String p []= bf.readLine().split(" ");
  76. String opstina = p[0];
  77. if(!opshtini.contains(opstina)){
  78. opshtini.add(opstina);
  79. }
  80. String prezime = p[1];
  81. String rezultat = p[2];
  82. Patient patient = new Patient(prezime, opstina, rezultat);
  83. patients.add(patient);
  84. }
  85.  
  86. for (String s: opshtini){
  87. int numberPositive = 0;
  88. int numberNegative = 0;
  89. for(Patient p: patients){
  90. if(p.getOpshtina().equals(s)){
  91. if(p.getPozitiven().equals("pozitiven")){
  92. numberPositive++;
  93. } else if(p.getPozitiven().equals("negativen")){
  94. numberNegative++;
  95. }
  96. }
  97. }
  98. negativePatients.insert(s, numberNegative);
  99. positivePatients.insert(s,numberPositive);
  100. }
  101.  
  102. String opstina = bf.readLine();
  103. // float total = negativePatients.search(opstina).element.value + positivePatients.search(opstina).element.value;
  104. // //System.out.println(total);
  105. // //System.out.println(negativePatients.search(opstina).element.value);
  106. // //System.out.println(positivePatients.search(opstina).element.value);
  107. // float numbPositive = positivePatients.search(opstina).element.value;
  108. // float riskFactor = numbPositive / total;
  109. System.out.println(negativePatients.search(opstina).element.value);
  110. System.out.println(positivePatients.search(opstina).element.value);
  111. // System.out.println(String.format("%.2f", riskFactor));
  112. // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  113. // int N = Integer.parseInt(br.readLine());
  114. //
  115. //
  116. // for(int i=0;i<N;i++){
  117. // String mesto_ime_rez = br.readLine();
  118. // String[] pom = mesto_ime_rez.split(" ");
  119. // if(pom[2].equals("pozitiven"))
  120. // addValuesPositive(pom[0],pom[1]);
  121. // if(pom[2].equals("negativen"))
  122. // negativni.insert(pom[0],pom[1]);
  123. // }
  124. //
  125. //
  126. // System.out.println(pozitivni);
  127. // System.out.println(negativni);
  128. // while (true) {
  129. // String line = br.readLine();
  130. // String parts [] = line.split(" ");
  131. // SLLNode<MapEntry<String,String>> temp = table.search(parts[0]);
  132. //
  133. // if (temp.getElement().value.equals(parts[1])){
  134. //
  135. //
  136. // }
  137. //
  138. // if (line.equals("Центар"))
  139. // break;
  140. //
  141. //
  142. // if (temp == null || !(temp.getElement().value.equals(parts[1])))
  143. // System.out.println("Nenajaven");
  144. // else {
  145. // System.out.println("Najaven");
  146. // break;
  147. // }
  148. //
  149. // }
  150.  
  151. }
  152. }
  153.  
  154. class CBHT<K extends Comparable<K>,E> {
  155.  
  156. private SLLNode<MapEntry<K,E>>[] buckets;
  157.  
  158. @SuppressWarnings("unchecked")
  159. public CBHT(int m) {
  160.  
  161. buckets = (SLLNode<MapEntry<K,E>>[]) new SLLNode[m];
  162. }
  163.  
  164. private int hash(K key) {
  165. // Translate key to an index of the array buckets.
  166. return Math.abs(key.hashCode()) % buckets.length;
  167. }
  168.  
  169. public SLLNode<MapEntry<K,E>> search(K targetKey) {
  170. // Find which if any node of this CBHT contains an entry whose key is
  171. // equal
  172. // to targetKey. Return a link to that node (or null if there is none).
  173. int b = hash(targetKey);
  174. SLLNode<MapEntry<K,E>> curr = buckets[b];
  175. for (; curr != null; curr = curr.succ) {
  176. if (targetKey.equals(curr.getElement().key)) {
  177. return curr;
  178. }
  179. }
  180. return null;
  181.  
  182. }
  183.  
  184. public void insert(K key, E value) {
  185.  
  186. MapEntry<K,E> newEntry = new MapEntry<K,E>(key, value);
  187. int b = hash(key);
  188. SLLNode<MapEntry<K,E>> curr = buckets[b];
  189. for (; curr != null; curr = curr.succ) {
  190. if (key.equals(curr.getElement().key)) {
  191. curr.setElement(newEntry);
  192. return;
  193. }
  194. }
  195. buckets[b] = new SLLNode<MapEntry<K,E>>(newEntry, buckets[b]);
  196. }
  197.  
  198. public void delete (K key) {
  199. // Delete the entry (if any) whose key is equal to key from this CBHT.
  200. int b = hash(key);
  201. SLLNode<MapEntry<K,E>> pred = null, curr = buckets[b];
  202. for (; curr != null; pred = curr, curr = curr.succ) {
  203. if (key.equals(curr.getElement().key)) {
  204. if (pred == null)
  205. buckets[b] = curr.succ;
  206. else
  207. pred.succ = curr.succ;
  208. return;
  209. }
  210. }
  211. }
  212.  
  213. public String toString() {
  214. String temp = "";
  215. for (int i = 0; i < buckets.length; i++) {
  216. temp += i + ":";
  217. for (SLLNode<MapEntry<K,E>> curr = buckets[i]; curr != null; curr = curr.succ) {
  218. temp += curr.getElement().toString() + " ";
  219. }
  220. temp += "\n";
  221. }
  222. return temp;
  223. }
  224.  
  225. }
  226.  
  227. class MapEntry<K extends Comparable<K>,E> implements Comparable<K> {
  228.  
  229. K key;
  230. E value;
  231.  
  232. public MapEntry(K key, E value) {
  233. this.key = key;
  234. this.value = value;
  235. }
  236.  
  237. @Override
  238. public int compareTo(K that) {
  239. return this.key.compareTo(that);
  240. }
  241.  
  242. @Override
  243. public String toString () {
  244. return "<" + key + "," + value + ">";
  245. }
  246. }
  247.  
  248. class SLLNode<E> {
  249.  
  250. protected E element;
  251. public SLLNode<E> succ;
  252.  
  253. public SLLNode(E element, SLLNode<E> succ) {
  254. this.setElement(element);
  255. this.succ = succ;
  256. }
  257.  
  258. @Override
  259. public String toString() {
  260. return getElement().toString();
  261. }
  262.  
  263. public E getElement() {
  264. return element;
  265. }
  266.  
  267. public void setElement(E element) {
  268. this.element = element;
  269. }
  270.  
  271. }
Advertisement
Add Comment
Please, Sign In to add comment