Advertisement
PecaJ

idk

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