Coding | Mcqs | Multiple choice questions | Informative | Computer Science | Engineering | Aptitude | Quants | Verbal

INFEED

Daily Challenge[05/04/2021]

#include<stdio.h>

#include<stdlib.h>

int R,C,mat[50][50];

int getRow(int val)

{

for(int i=0;i<R;i++)

{

for(int j=0;j<C;j++)

{

if(mat[i][j]==val)

{

return i;

}

}

}

}

int getCol(int val)

{

for(int i=0;i<R;i++)

{

for(int j=0;j<C;j++)

{

if(mat[i][j]==val)

{

return j;

}

}

}

}

int main()

{

scanf("%d %d",&R,&C);

int arr[1001],k=0;

int totalDistance = 0;

for(int i=0;i<k-1;i++)

{

int p1 = arr[i];

int p2 = arr[i+1];

int currDistance = abs(getRow(p1)-getRow(p2)) + abs(getCol(p1)-getCol(p2));

totalDistance += currDistance; 

}

printf("%d",totalDistance);

}

Post a Comment

Previous Post Next Post