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
0985 - cifre11
(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!
== Rezolvare == <syntaxhighlight lang="python" line="1"> # 0985 - cifre11 # Funcția de validare: verifică dacă numărul citit este valid def validare(nr): # Numărul trebuie să aibă cel puțin două cifre if nr < 10: return False # Suma cifrelor trebuie să fie impară s = 0 while nr > 0: s += nr % 10 nr //= 10 if s % 2 == 0: return False return True # Funcția pentru cerința a) def suma_cif_min(nums): min_sum = float('inf') max_nr = -1 for nr in nums: s = sum(int(c) for c in str(nr)) if s < min_sum: min_sum = s max_nr = nr elif s == min_sum and nr > max_nr: max_nr = nr return max_nr # Funcția pentru cerința b) def cifre_consecutive(nums): max_nr = float('inf') max_ct = -1 for nr in nums: str_nr = str(nr) ct = 1 for i in range(1, len(str_nr)): if int(str_nr[i]) == int(str_nr[i - 1]) + 1: ct += 1 else: ct = 1 if ct > max_ct: max_ct = ct max_nr = nr elif ct == max_ct and nr < max_nr: max_nr = nr return max_nr # Funcția pentru cerința c) def cifra_comuna(nums): freq = [0] * 10 for nr in nums: for c in str(nr): freq[int(c)] += 1 max_freq = max(freq) cifre = [] for i in range(1, 10): if freq[i] == max_freq: cifre.append(i) return cifre # Funcția main: citește datele de intrare și apelează funcțiile corespunzătoare if __name__ == "__main__": try: # Citire date din fisierul de intrare with open("cifre11.in", "r") as fin: n = int(fin.readline().strip()) nums = list(map(int, fin.readline().strip().split())) for i in range(n): line = fin.readline().strip() nums += list(map(int, line.split())) # Verificare validitate date de intrare if len(nums) < n: raise ValueError("Datele nu corespund restricțiilor impuse.") # Afișare mesaj pentru date de intrare valide print("Datele sunt introduse corect.") # Rezolvare cerințe rez_cerinta_a = suma_cif_min(nums) rez_cerinta_b = cifre_consecutive(nums) rez_cerinta_c = cifra_comuna(nums) # Scriere rezultate in fisierul de iesire with open("cifre11.out", "w") as fout: fout.write(str(rez_cerinta_a) + "\n") fout.write(str(rez_cerinta_b) + "\n") fout.write(" ".join(str(c) for c in rez_cerinta_c)) except Exception as e: print("Eroare:", str(e)) </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