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
4163 - Seif
(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> def citire_date(): with open("seif.in", "r") as f: N = int(f.readline().strip()) matrice = [list(map(int, f.readline().strip().split())) for _ in range(N)] T = int(f.readline().strip()) operatii = [f.readline().strip().split() for _ in range(T)] operatii = [(int(op[0]), int(op[1]), op[2]) for op in operatii] return N, matrice, T, operatii def extrage_chenar(matrice, chenar, N): elementi = [] start = chenar - 1 end = N - chenar for j in range(start, end + 1): elementi.append(matrice[start][j]) for i in range(start + 1, end + 1): elementi.append(matrice[i][end]) for j in range(end - 1, start - 1, -1): elementi.append(matrice[end][j]) for i in range(end - 1, start, -1): elementi.append(matrice[i][start]) return elementi def insereaza_chenar(matrice, chenar, N, elementi): index = 0 start = chenar - 1 end = N - chenar for j in range(start, end + 1): matrice[start][j] = elementi[index] index += 1 for i in range(start + 1, end + 1): matrice[i][end] = elementi[index] index += 1 for j in range(end - 1, start - 1, -1): matrice[end][j] = elementi[index] index += 1 for i in range(end - 1, start, -1): matrice[i][start] = elementi[index] index += 1 def permutare_circulara(elementi, pozitii, sens): lungime = len(elementi) pozitii = pozitii % lungime if sens == 'S': return elementi[pozitii:] + elementi[:pozitii] elif sens == 'D': return elementi[-pozitii:] + elementi[:-pozitii] def aplica_operatii(N, matrice, operatii): for chenar, pozitii, sens in operatii: elementi = extrage_chenar(matrice, chenar, N) elementi_permutati = permutare_circulara(elementi, pozitii, sens) insereaza_chenar(matrice, chenar, N, elementi_permutati) def scrie_rezultate(matrice): with open("seif.out", "w") as f: for linie in matrice: f.write(" ".join(map(str, linie)) + "\n") def main(): N, matrice, T, operatii = citire_date() # Verificarea restrictiilor assert 2 <= N <= 500, "N trebuie sa fie intre 2 si 500" assert N % 2 == 0, "N trebuie sa fie par" assert 1 <= T <= 100000, "T trebuie sa fie intre 1 si 100.000" for op in operatii: assert 1 <= op[1] <= 1000000, "Numarul de pozitii trebuie sa fie intre 1 si 1.000.000" assert op[2] in ['S', 'D'], "Sensul trebuie sa fie 'S' sau 'D'" aplica_operatii(N, matrice, operatii) scrie_rezultate(matrice) 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