Advertisement
Aikiro42

timothy_pa1

Jan 26th, 2020
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.72 KB | None | 0 0
  1. T = int(input())
  2.  
  3. solved_grids = []
  4. # Store your solved grids here for easy printing
  5.  
  6. i = 0
  7. while i < T:
  8.     # Get input
  9.     # rcMN = input()
  10.     # print(rcMN)
  11.     # r, c, M, N = rcMN.split()  # splitting input
  12.     # protip:
  13.     r, c, M, N = map(int, input().split())
  14.     # this is basically
  15.     # string = input()
  16.     # r = int(string.split()[0])
  17.     # c = int(string.split()[1])
  18.     # M = int(string.split()[2])
  19.     # N = int(string.split()[3])
  20.  
  21.     G = []
  22.     # j = 0
  23.  
  24.     # arrange horizontally
  25.     # G1 = []
  26.     # no need for extra storage if you can do the work on the variable itself
  27.     # for x in range(int(r)):
  28.     #     line = input().split(" ")
  29.     #     # G1.append(line)
  30.     #     G.append(line)
  31.     # btw, another protip:
  32.     G = [input().split(" ") for _ in range(r)]
  33.     # list comprehension is a thing. I recommend you take a look at it
  34.     # Don't overuse it though.
  35.     # The point is not to make your code shorter, it's to make it simpler.
  36.     # Sure you have 1 line of code for a solution but could you really get it
  37.     # the first time you've read it?
  38.  
  39.     # rotate
  40.     # G2 = []
  41.     # no need for an extra array
  42.  
  43.     # for each element in g
  44.     for x in range(len(G)):
  45.         # G2a = G1[x][int(M) - 1:] + G1[x][:int(M) - 1]  # slices the list at M
  46.         # G2.append(G2a)
  47.         G[x] = G[x][-(M % c):] + G[x][:-(M % c)]
  48.         # Notice the modulo? What are we gonna do if we shift a 5-element array 6 units to the right?
  49.         # 11 units to the right?
  50.  
  51.     # arrange vertically
  52.     """G3 = []
  53.    for x in range(int(c)):
  54.        newrow = []
  55.        for y in range(int(r)):
  56.            z = G2[y][x]
  57.            newrow.append(int(z))
  58.        G3.append(newrow) """
  59.     # switcheroo
  60.     # G4 = []
  61.     # for x in range(len(G2)):
  62.     #     G4a = G2[x][int(N):] + G2[x][:int(N)]  # slices the string at M
  63.     #     G4.append(G4a)
  64.     # print(G4[2][0])
  65.     # print(G4)
  66.  
  67.     # you know, if you think about it, shifting elements up is literally
  68.     # shifting the rows up, which means you're shifting whole lists.
  69.     # ...if you think about it you're actually shifting the lists
  70.     # in the grid LEFTWARDS.
  71.  
  72.     G = G[(N % r):] + G[:(N % r)]
  73.  
  74.     # grid solved!
  75.     solved_grids.append(G)
  76.  
  77.     # arranging output
  78.  
  79.     # traverse all sublists and append the kth element of each
  80.  
  81.     # c1 = 0
  82.     # while c1 < len(G4):
  83.     #     newer_row = []
  84.     #     c2 = 0
  85.     #     while c2 < len(G4[c1]):
  86.     #         newer_row.append(G4[c1][c2])
  87.     #         c2 += 1
  88.     #         print(newer_row)
  89.     #     c1 += 1
  90.  
  91.     i += 1
  92.  
  93. # Look up for each
  94. # All for loops in python are for each loops.
  95. for grid in solved_grids:
  96.     for row in grid:
  97.         print(' '.join(row))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement