CF 3A Shortest path of the king

这题我傻逼还用BFS。看了别人的代码我彻底无语~

#include <stdio.h>
#include <iostream>
#include <stdlib.h>
using namespace std;


int main()
{
    string a,b;
    while(cin>>a>>b)
    {
        int m = abs(a[0]-b[0]);
        int n = abs(a[1]-b[1]);
        cout<<max(m,n)<<endl;
        while(a!=b)
        {
            if(a[0] > b[0]) {cout<<"L";a[0] --;}
            if(a[0] < b[0]) {cout<<"R";a[0] ++;}
            if(a[1] > b[1]) {cout<<"D";a[1] --;}
            if(a[1] < b[1]) {cout<<"U";a[1] ++;}
            cout<<endl;
        }
    }
}


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