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
2644 - Clase
(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 ver. 1=== <syntaxhighlight lang="python" line="1" start="1"> def validate_input(): # Citim datele de intrare n = int(input().strip()) classes = list(map(int, input().strip().split())) m = int(input().strip()) packages = list(map(int, input().strip().split())) # Validam inputul assert 1 <= n <= 10000, "Numarul de clase trebuie sa fie intre 1 si 10000" assert 1 <= m <= 10000, "Numarul de pachete trebuie sa fie intre 1 si 10000" for c in classes: assert 1 <= c <= 10**12, "Numarul de elevi trebuie sa fie intre 1 si 10^12" for p in packages: assert 1 <= p <= 10**12, "Numarul de carti trebuie sa fie intre 1 si 10^12" def count_classes_with_packages(n, classes, m, packages): # Initializam un set cu clasele care primesc pachete cu carti classes_with_packages = set() # Parcurgem toate pachetele cu carti for package in packages: # Parcurgem toate clasele si verificam daca numarul de elevi # dintr-o clasa este egal cu numarul de carti din pachet for i in range(n): if classes[i] == package: classes_with_packages.add(i+1) # Returnam numarul de clase care primesc pachete cu carti return len(classes_with_packages) def main(): # Validam inputul validate_input() # Citim datele de intrare n = int(input().strip()) classes = list(map(int, input().strip().split())) m = int(input().strip()) packages = list(map(int, input().strip().split())) # Determinam numarul de clase care primesc pachete cu carti num_classes_with_packages = count_classes_with_packages(n, classes, m, packages) # Afisam rezultatul in consola si in fisierul de iesire with open("clase.out", "w") as fout: fout.write(str(num_classes_with_packages) + "\n") print(num_classes_with_packages) 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