Advertisement
PecaJ

trying to ease pekino mucenje

Jan 14th, 2021
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. def unos_podataka():
  2. ulaz = input().split()
  3. ulazni_file = ulaz[0]
  4. izlazni_file = ulaz[1]
  5.  
  6. broj_mandata = int(input())
  7.  
  8. godine = input().split()
  9. temp = []
  10. for i in godine:
  11. temp.append(int(i))
  12. godine = temp
  13. fin = open(ulazni_file, 'r')
  14. lines = []
  15. for line in fin:
  16. lines.append(line)
  17. fin.close()
  18. return izlazni_file, broj_mandata, godine, lines
  19.  
  20. def obrada_podataka(broj_mandata, godine, lines):
  21. kolicnik1 = 0
  22. kolicnik2 = 0
  23. kolicnik3 = 0
  24. kolicnik4 = 0
  25. kolicnik5 = 0
  26. kolicnik6 = 0
  27. lista_kolicnika = []
  28. maks = 0
  29. linije = []
  30.  
  31. for line in lines:
  32. suma = 0
  33. cenzus = 0
  34. number_of_votes = []
  35. mandati1 = 0
  36. mandati2 = 0
  37. mandati3 = 0
  38. mandati4 = 0
  39. mandati5 = 0
  40. mandati6 = 0
  41. mandati = []
  42. number_of_votes = line.split('|')
  43. number_of_votes[6] = number_of_votes[6].rstrip()
  44. for i in range(0, len(number_of_votes)):
  45. number_of_votes[i] = int(number_of_votes[i])
  46. #suma
  47. for i in range(1, len(number_of_votes)):
  48. suma += number_of_votes[i]
  49. #cenzus
  50. cenzus = (5*suma)/100
  51. #racunanje mandata
  52. for i in range(0, broj_mandata):
  53. if number_of_votes[1] > cenzus:
  54. kolicnik1 = number_of_votes[1]/(1+mandati1)
  55. lista_kolicnika.append(kolicnik1)
  56. if number_of_votes[2] > cenzus:
  57. kolicnik2 = number_of_votes[2]/(1+mandati2)
  58. lista_kolicnika.append(kolicnik2)
  59. if number_of_votes[3] > cenzus:
  60. kolicnik3 = number_of_votes[3]/(1+mandati3)
  61. lista_kolicnika.append(kolicnik3)
  62. if number_of_votes[4] > cenzus:
  63. kolicnik4 = number_of_votes[4]/(1+mandati4)
  64. lista_kolicnika.append(kolicnik4)
  65. if number_of_votes[5] > cenzus:
  66. kolicnik5 = number_of_votes[5]/(1+mandati5)
  67. lista_kolicnika.append(kolicnik5)
  68. if number_of_votes[6] > cenzus:
  69. kolicnik6 = number_of_votes[6]/(1+mandati6)
  70. lista_kolicnika.append(kolicnik6)
  71. maks = max(lista_kolicnika)
  72. if maks == kolicnik1:
  73. mandati1 += 1
  74. if maks == kolicnik2:
  75. mandati2 += 1
  76. if maks == kolicnik3:
  77. mandati3 += 1
  78. if maks == kolicnik4:
  79. mandati4 += 1
  80. if maks == kolicnik5:
  81. mandati5 += 1
  82. if maks == kolicnik6:
  83. mandati6 += 1
  84. kolicnik1 = 0
  85. kolicnik2 = 0
  86. kolicnik3 = 0
  87. kolicnik4 = 0
  88. kolicnik5 = 0
  89. kolicnik6 = 0
  90. lista_kolicnika = []
  91. maks = 0
  92. mandati.append(mandati1)
  93. mandati.append(mandati2)
  94. mandati.append(mandati3)
  95. mandati.append(mandati4)
  96. mandati.append(mandati5)
  97. mandati.append(mandati6)
  98.  
  99. for godina in godine:
  100. temp = ''
  101. if godina == number_of_votes[0]:
  102. for mandat in mandati:
  103. if mandat > 50*(broj_mandata/100):
  104. mandat = mandati.index(mandat)
  105. temp = mandat
  106. if temp == '':
  107. temp = -1
  108. final.append(temp)
  109.  
  110. #jedna linija izlaznog fajla
  111. l = str(number_of_votes[0])
  112. for mandat in mandati:
  113. l += " "+str(mandat)
  114. #cuvaju se za prosledjivanje u ispis
  115. linije.append(l)
  116.  
  117.  
  118. temp = []
  119. for i in final:
  120. if i != '':
  121. temp.append(int(i))
  122. final = temp
  123. temp = sorted(godine)
  124. final_result = []
  125. for godina in godine:
  126. index = temp.index(godina)
  127. final_result.append(str(final[index]))
  128.  
  129.  
  130. return final_result, linije
  131.  
  132.  
  133.  
  134. def ispis_podataka(izlazni_file, final_results, linije):
  135. fout = open(izlazni_file, 'w')
  136. for l in linije:
  137. print(l, file=fout)
  138. fout.close()
  139.  
  140. print(' '.join(final_result))
  141.  
  142.  
  143.  
  144. try:
  145. izlazni_file, broj_mandata, godine, lines = unos_podataka()
  146. final_result, linije = obrada_podataka(broj_mandata, godine, lines)
  147. ispis_podataka(izlazni_file, final_results, linije)
  148. except FileNotFoundError:
  149. print(DAT_GRESKA)
  150. except Exception:
  151. print(GRESKA)
  152.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement