Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def unos_podataka():
- ulaz = input().split()
- ulazni_file = ulaz[0]
- izlazni_file = ulaz[1]
- broj_mandata = int(input())
- godine = input().split()
- temp = []
- for i in godine:
- temp.append(int(i))
- godine = temp
- fin = open(ulazni_file, 'r')
- lines = []
- for line in fin:
- lines.append(line)
- fin.close()
- return izlazni_file, broj_mandata, godine, lines
- def obrada_podataka(broj_mandata, godine, lines):
- kolicnik1 = 0
- kolicnik2 = 0
- kolicnik3 = 0
- kolicnik4 = 0
- kolicnik5 = 0
- kolicnik6 = 0
- lista_kolicnika = []
- maks = 0
- linije = []
- final = []
- for line in lines:
- suma = 0
- cenzus = 0
- number_of_votes = []
- mandati1 = 0
- mandati2 = 0
- mandati3 = 0
- mandati4 = 0
- mandati5 = 0
- mandati6 = 0
- mandati = []
- number_of_votes = line.split('|')
- number_of_votes[6] = number_of_votes[6].rstrip()
- for i in range(0, len(number_of_votes)):
- number_of_votes[i] = int(number_of_votes[i])
- #suma
- for i in range(1, len(number_of_votes)):
- suma += number_of_votes[i]
- #cenzus
- cenzus = (5*suma)/100
- #racunanje mandata
- for i in range(0, broj_mandata):
- if number_of_votes[1] > cenzus:
- kolicnik1 = number_of_votes[1]/(1+mandati1)
- lista_kolicnika.append(kolicnik1)
- if number_of_votes[2] > cenzus:
- kolicnik2 = number_of_votes[2]/(1+mandati2)
- lista_kolicnika.append(kolicnik2)
- if number_of_votes[3] > cenzus:
- kolicnik3 = number_of_votes[3]/(1+mandati3)
- lista_kolicnika.append(kolicnik3)
- if number_of_votes[4] > cenzus:
- kolicnik4 = number_of_votes[4]/(1+mandati4)
- lista_kolicnika.append(kolicnik4)
- if number_of_votes[5] > cenzus:
- kolicnik5 = number_of_votes[5]/(1+mandati5)
- lista_kolicnika.append(kolicnik5)
- if number_of_votes[6] > cenzus:
- kolicnik6 = number_of_votes[6]/(1+mandati6)
- lista_kolicnika.append(kolicnik6)
- maks = max(lista_kolicnika)
- if maks == kolicnik1:
- mandati1 += 1
- if maks == kolicnik2:
- mandati2 += 1
- if maks == kolicnik3:
- mandati3 += 1
- if maks == kolicnik4:
- mandati4 += 1
- if maks == kolicnik5:
- mandati5 += 1
- if maks == kolicnik6:
- mandati6 += 1
- kolicnik1 = 0
- kolicnik2 = 0
- kolicnik3 = 0
- kolicnik4 = 0
- kolicnik5 = 0
- kolicnik6 = 0
- lista_kolicnika = []
- maks = 0
- mandati.append(mandati1)
- mandati.append(mandati2)
- mandati.append(mandati3)
- mandati.append(mandati4)
- mandati.append(mandati5)
- mandati.append(mandati6)
- for godina in godine:
- temp = ''
- if godina == number_of_votes[0]:
- for mandat in mandati:
- if mandat > 50*(broj_mandata/100):
- mandat = mandati.index(mandat)
- temp = mandat
- if temp == '':
- temp = -1
- final.append(temp)
- #jedna linija izlaznog fajla
- l = str(number_of_votes[0])
- for mandat in mandati:
- l += " "+str(mandat)
- #cuvaju se za prosledjivanje u ispis
- linije.append(l)
- temp = []
- for i in final:
- if i != '':
- temp.append(int(i))
- final = temp
- temp = sorted(godine)
- final_result = []
- for godina in godine:
- index = temp.index(godina)
- final_result.append(str(final[index]))
- return final_result, linije
- def ispis_podataka(izlazni_file, final_result, linije):
- fout = open(izlazni_file, 'w')
- for l in linije:
- print(l, file=fout)
- fout.close()
- print(' '.join(final_result))
- # try:
- izlazni_file, broj_mandata, godine, lines = unos_podataka()
- final_result, linije = obrada_podataka(broj_mandata, godine, lines)
- ispis_podataka(izlazni_file, final_result, linije)
- # except FileNotFoundError:
- # print("DAT_GRESKA")
- # except Exception:
- # print("GRESKA")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement