codeforces-3A Shortest path of the king

题意:在棋盘上给定两点坐标,输出最短到达步数及路径。

#include 
main(){

    int x,y;
    char x1,y1,x2,y2,h,v;

    scanf("%c%c",&x1,&y1);
    getchar();
    scanf("%c%c",&x2,&y2);

    x=x2-x1;
    y=y2-y1;

    h=((x<0)?x=-x,'L':'R');//确定方向
    v=((y<0)?y=-y,'D':'U');
    printf("%d\n",x>y?x:y);
    while(x|y){
        if(x)x--,putchar(h);
        if(y)y--,putchar(v);
        printf("\n");
    }
}

你可能感兴趣的:(codeforces-3A Shortest path of the king)