Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Bitnami MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
1056 - Unific
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
= Explicație = Cifra care apare cel mai frecvent este <code>3</code> (de <code>6</code> ori). Se unifică: <code>47</code> cu <code>67 => 46</code>. Şirul rămas: <code>6 46 40 123 231 1238 331 2035 50007</code> Se unifică: <code>6</code> cu <code>46 => 4</code>. Şirul rămas: <code>4 40 123 231 1238 331 2035 50007</code> Se unifică: <code>4</code> cu <code>40 => 0</code>. Şirul rămas: <code>0 123 231 1238 331 2035 50007</code> Se unifică: <code>123</code> cu <code>231</code>, ambele numere rămân fără cifre, deci vor fi ambele eliminate. Şirul rămas: <code>0 1238 331 2035 50007</code> Se unifică: <code>1238</code> cu <code>331 => 28</code>. Şirul rămas: <code>0 28 2035 50007</code> Se unifică: <code>28</code> cu <code>2035 => 835</code>. Şirul rămas: <code>0 835 50007</code> Se unifică: <code>835</code> cu <code>50007 => 837</code>. Şirul rămas: <code>0 837</code> == Exemplul 1: == <code>unificIN.txt</code> 100001 6 47 67 40 123 231 1238 331 2035 50007 <code>unificOUT.txt</code> Datele nu corespund restrictiilor impuse == Rezolvare == <syntaxhighlight lang="python3" line="1"> def verifica_restrictii(n, numere): if not (1 <= n <= 100000): return False for numar in numere: if not (0 <= numar <= 10**18): return False return True def main(): with open("unificIN.txt", "r") as fin, open("unificOUT.txt", "w") as fout: n = int(fin.readline().strip()) numere = [] for _ in range(n): line = fin.readline().strip() if line: numere.append(int(line)) if not verifica_restrictii(n, numere): fout.write("Datele nu corespund restrictiilor impuse") return frec = [0] * 11 st = [] def cifre(x): while x: frec[x % 10] += 1 x //= 10 def verif(poz): aux1 = [0] * 11 x = st[poz - 1] if x == 0: aux1[0] += 1 while x: aux1[x % 10] += 1 x //= 10 y = st[poz] if y == 0 and aux1[0] != 0: return 1 while y: if aux1[y % 10] != 0: return 1 y //= 10 return 0 def getnum(dr): f = [0] * 21 unu = [0] * 21 doi = [0] * 21 cif1, cif2 = 0, 0 x, y = st[dr - 1], st[dr] st_num, drr = 0, 0 concatenate = False ok = False if x == 0: f[0] += 1 unu[cif1] = 0 cif1 += 1 if y == 0: f[0] += 1 doi[cif2] = 0 cif2 += 1 while x: cif1 += 1 unu[cif1] = x % 10 f[x % 10] += 1 x //= 10 while y: if f[y % 10] != 0: f[y % 10] = -1 cif2 += 1 doi[cif2] = y % 10 y //= 10 for i in range(cif1, 0, -1): if f[unu[i]] != -1: st_num = 10 * st_num + unu[i] ok = True for i in range(cif2, 0, -1): if f[doi[i]] != -1: drr = 10 * drr + doi[i] ok = True concatenate = True if not ok: return -1 if concatenate: p = 10 while drr >= p: p *= 10 return st_num * p + drr return st_num for numar in numere: cifre(numar) st.append(numar) while len(st) >= 2 and verif(len(st) - 1): x = getnum(len(st) - 1) if x != -1: st[-2] = x st.pop() else: st.pop() st.pop() maxi, afis = max((val, idx) for idx, val in enumerate(frec)) fout.write(f'{afis}\n') fout.write(f'{len(st)}\n') for numar in st: fout.write(f'{numar} ') if __name__ == "__main__": main() </syntaxhighlight>
Summary:
Please note that all contributions to Bitnami MediaWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Bitnami MediaWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width