The king is left alone on the chessboard. In spite of this loneliness, he doesn’t lose heart, because he has a business of national importance.
For example, he has to pay an official visit to square T.
As the king is not in habit of wasting his time, he wants to get from his current position S to square T in the least number of moves.
Help him to do this.
In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).
Input:
The first line contains the chessboard coordinates of square s
The second line — of square t.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.
Output:
In the first line print n — a minimum number of the king's moves.
Then in n lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU, or RD.
L, R, U, D stand respectively for moves left, right, up, and down, and 2-letter combinations stand for diagonal moves.
If the answer is not unique, print any of them.
#include <stdio.h> #include <stdlib.h> #include<stdio.h> struct king { char cy[5],cx[5]; }; int main() { struct king path; scanf("%s%s",path.cy,path.cx); int x=path.cx[0]-path.cy[0]; int y=path.cx[1]-path.cy[1]; abs(x>y)?printf("%d\n",abs(x)):printf("%d\n",abs(y)); while(x||y){ if(x>0){ x--;printf("R");} if(x<0){ x++;printf("L");} if(y>0){ y--;printf("U");} if(y<0){ y++;printf("D"); } printf("\n"); } return 0; }
INPUT_1:
a8
h1
OUTPUT:
7
RD
RD
RD
RD
RD
RD
RD
INPUT_2:
a4
h7
OUTPUT:
7
RU
RU
RU
R
R
R
R
ILLUSTRATION
Morae Q!
- Find how long will it take till the next fortune year from the current year.
- Find if it’s possible to distribute all the crayons into boxes and satisfy all the conditions.
- Compute sum of numbers using call by reference.
- Compute the amount of money to be handed over with conditions.
- Find the total number of beautiful triplets in the sequence.
- Find the total amount each worker has to pay individually.
- Find the minimum distance between any pair of equal elements in the array.
- Compute the maximum possible value of the given equation.
- Find the age of the student at the time of joining.
- Compute the total number of photos at each restaurant .
- Find the sum of digits of the number using Union datatype.
- Generate the details of the novels in the expected format.
- Sort the student details based on their names in ascending order.
- Find a way to move the king from current position to different square on chessboard.
- Find the time differences in the two different time zones.
- Identifying the greatest number with a numerator and denominator.
- Find the Minimum number of packages to supply all the bases.
- Tower of Hanoi, A puzzle.
- Compute the sum of array of elements using recursion method.
- Find the super digit of an integer using the rules.