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
2484 - Key
(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"> #2484 key with open('key.in', 'r') as f: p, door_code, n = f.readline().split() n = int(n) keys = [] for i in range(n): key_code, price = f.readline().split() keys.append((key_code, int(price))) stricate = deteriorate = slab_deteriorate = bune = 0 total_cost = 0 def validate_input(p, door_code, n, keys): if p not in ['1', '2']: return False, "Valoarea lui P trebuie să fie '1' sau '2'." if not door_code.isalpha() or len(door_code) != 3: return False, "Codul ușii trebuie să conțină exact 3 litere." if not (1 <= n <= 1000): return False, "Numărul de chei (n) trebuie să fie între 1 și 1000." if len(keys) != n: return False, "Numărul de chei specificat nu corespunde cu numărul real de chei." for key_code, price in keys: if not key_code.isalpha() or len(key_code) != 3 or not key_code.isupper(): return False, "Codul cheii trebuie să conțină exact 3 litere majuscule." try: price = int(price) if not (1 <= price <= 10000): return False, "Prețul cheii trebuie să fie între 1 și 10000." except ValueError: return False, "Prețul cheii trebuie să fie un număr întreg." return True, None def main(): with open('key.in', 'r') as f, open('key.out', 'w', encoding='utf-8') as output_file: try: p, door_code, n = f.readline().split() n = int(n) keys = [f.readline().split() for _ in range(n)] except ValueError: output_file.write("Date de intrare invalide.") return is_valid, error_message = validate_input(p, door_code, n, keys) if not is_valid: output_file.write("Numar invalid: " + error_message) return keys = [(key_code, int(price)) for key_code, price in keys] stricate = deteriorate = slab_deteriorate = bune = 0 total_cost = 0 for key_code, price in keys: num_matches = sum(key_code[i] == door_code[i] for i in range(3)) if num_matches == 0: stricate += 1 total_cost += price elif num_matches == 1: deteriorate += 1 total_cost += price * 2 / 3 elif num_matches == 2: slab_deteriorate += 1 total_cost += price / 3 else: bune += 1 if p == '1': output_file.write(f"{stricate} {deteriorate} {slab_deteriorate} {bune}") else: if bune == n or total_cost == 0: output_file.write("GRATIS") else: output_file.write(str(int(total_cost))) 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