Robotics sum-1
Problem the input "R","L","U","D" denotes to right, left, up and down respectively.
Input
- If it consists of "R" move one point towards right in the graph.
- If it consists of "L" move one point towards left in the graph.
- If it consists of "U" move one point upwards in the graph.
- If it consists of "D" move one point downwards in the graph.
output
- After performing all the process print the X and Y coordinates.
Example-1:
Input : n = "RRLDDUUU" Output : 1 1 Explain : The final output is x=1 and y=1
Example-2:
Input : n = "RLDU" Output : 0 0 Explain : The final output is x=0 and y=0.
Example-3:
Input : n = "RRLUU" Output : 1 2 Explain : The final output is x=1 and y=2.
Solution
n = "RRLDDUUU" x = 0 y = 0 for i in n: if(i=="R"): x+=1 if(i=="L"): x-=1 if(i=="U"): y+=1 if(i=="D"): y-=1 print(x,y)
Output
1 1