Solution in c++
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
string aa,bb;
cin>>aa>>bb;
int x1=aa[0]-'a',x2=bb[0]-'a',y1=aa[1]-'1',y2=bb[1]-'1';
int cr=min(abs(x1-x2),abs(y1-y2));
int all=abs(x1-x2)+abs(y1-y2)-cr;
cout<<all<<"\n";
while(all--){
if(x1<x2){cout<<"R";x1++;}else if (x1>x2) {cout<<"L";x1--;}
if(y1<y2){cout<<"U";y1++;}else if (y1>y2) {cout<<"D";y1--;}
cout<<"\n";
}
return 0;
}
0 التعليقات:
إرسال تعليق