这种题一般都是用bfs做的。。。。不过好像这样更简单。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <algorithm>
#include <cctype>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <iomanip>
#include <set>
#include <vector>
#include <cstdio>
#include <stack>
#include <sstream>
#include <cstring>
#include <map>
using namespace std;
int main()
{
string str1,str2;
cin>>str1>>str2;
int xd=str1[0]-str2[0];
int yd=str1[1]-str2[1];
char x,y;
if(xd<0)
x='R';
else
x='L';
if(yd<0)
y='U';
else
y='D';//判断终点在起点的哪个方位
int dx=abs(xd),dy=abs(yd);
int step=max(dx,dy);
printf("%d\n",step);
while(dx||dy)
{
if(dx)
{
cout<<x;
dx--;
}
if(dy)
{
cout<<y;
dy--;
}
cout<<endl;
}
return 0;
}