Here's your approach:
Create a array to store the matrix.
Use nested loops to read the input: outer loop for rows ( to ), inner loop for columns ( to ).
While reading, check if the current element is . If yes, remember its row and column.
After finding the at position , compute the distance: distance = abs(r - 3) + abs(c - 3).
Output the distance. That's the minimum number of swaps needed.