Matrix Unit Digit Swap

 Coding Problem Keys 

 Matrix Unit Digit Swap 

 Problem Statement 

The program must accept an integer matrix of size R*C, where C is even and swap the unit digits of the elements in columns 1 and 2, then 3 and 4 and so on till columns C-1 and C. Then the program must print the revised matrix as the output.

 Input Format 

The first line contains the value of R and C separated by space(s).
The next R lines each containing C integer values separated by a space.

 Output Format 

R lines each containing C integer values separated by a space.

 Constraints 

1 <= R, C
 <= 100
1 <= Value of an element in the matrix <= 1000

 Example Input/Output 1 

 Input 

3 4
96 61 138 32
150 67 131 177
172 103 83 45

 Output 

91 66 132 38
157 60 137 171
173 102 85 43

 Max Execution Time Limit: 1000 millisecs 

 Solution 

 Programming Language: Python 3 Language 

r,c=map(int,input().split())
l=[list(map(int,input().split())) for i in range(r)]
for i in range(r):
    for j in range(c):
        if(j%2==0):
            l[i][j],l[i][j+1]=(l[i][j]//10*10)+(l[i][j+1]%10),l[i][j+1]//10*10+l[i][j]%10
for i in range(r):
    for j in range(c):
        print(l[i][j],end=" ")
    print()

# Published By PKJCODERS

 (Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.) 

Comments

Popular Posts

Snakes and Ladders

Sort integers in String

Flowchart Logic 065

Reverse Column - First and Last

Alphabetical Order Pattern

String With Most Vowels