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
4256 - Oglindire Secvente
(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!
= Restricții și precizări = * <code>1 ≤ k < n ≤ 1000</code>, <code>k</code> este divizor al lui <code>n</code> * cele <code>n</code> numere citite vor fi mai mici decât <code>1000</code> == Exemplul 1 == Input: 15 5 3 6 4 7 6 6 6 4 6 7 6 6 4 4 5 Output: 6 7 4 6 3 7 6 4 6 6 5 4 4 6 6 Explicație: Vectorul se împarte în <code>3</code> secvențe de lungime <code>5</code>: <code>(3 6 4 7 6)</code>, <code>(6 6 4 6 7)</code>și <code>(6 6 4 4 5)</code>. Elementele din fiecare dintre ele se oglindesc și se obține secvențele <code>(6 7 4 6 3)</code>, <code>(7 6 4 6 6)</code> și <code>(5 4 4 6 6)</code>. == Exemplul 2 == Input: 15 76 3 6 4 7 6 6 6 4 6 7 6 6 4 4 5 Output: Restricții neîndeplinite. == Rezolvare == <syntaxhighlight lang="python3" line="1"> def validate_input(n, k, vector): if not (1 < k < n <= 1000) or any(x >= 1000 for x in vector): print("Restricții neîndeplinite.") return False if n % k != 0: print("k trebuie să fie divizor al lui n.") return False return True def citire(): n = int(input("Introduceți n: ")) k = int(input("Introduceți k: ")) # Read the entire line, split it into a list of strings, and convert each string to an integer vector = list(map(int, input().split())) return n, k, vector def afisare(vector): print(" ".join(map(str, vector))) def oglindire(st, dr, vector): while st < dr: vector[st], vector[dr] = vector[dr], vector[st] st += 1 dr -= 1 def main(): n, k, vector = citire() # Verificare validitate input if not validate_input(n, k, vector): return # Afisare vector initial print("Vectorul initial:") afisare(vector) # Oglindire si afisare vector modificat for i in range(0, n, k): st = i dr = min(i + k - 1, n - 1) oglindire(st, dr, vector) print("Vectorul dupa oglindire:") afisare(vector) 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