Position of robot after given movements | C # implementation to find final position of robot after the complete movement ; function to find final position of robot after the complete movement ; traverse the instruction string ' move ' ; for each movement increment its respective counter ; required final position of robot ; Driver code
using System ; class GFG { static void finalPosition ( String move ) { int l = move . Length ; int countUp = 0 , countDown = 0 ; int countLeft = 0 , countRight = 0 ; for ( int i = 0 ; i < l ; i ++ ) { if ( move [ i ] == ' U ' ) countUp ++ ; else if ( move [ i ] == ' D ' ) countDown ++ ; else if ( move [ i ] == ' L ' ) countLeft ++ ; else if ( move [ i ] == ' R ' ) countRight ++ ; } Console . WriteLine ( " Final ▁ Position : ▁ ( " + ( countRight - countLeft ) + " , ▁ " + ( countUp - countDown ) + " ) " ) ; } public static void Main ( ) { String move = " UDDLLRUUUDUURUDDUULLDRRRR " ; finalPosition ( move ) ; } }