The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has 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 — 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 (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them.

Examples

Input
a8
h1
Output
7
RD
RD
RD
RD
RD
RD
RD     cf此题地址http://codeforces.com/problemset/problem/3/A     这里学到了string这个东西。比如,string a; a[0]="adasdasd",第一次知道还有这种操作,一位存一个字符串,那么就简单多了。
    那么使用while模拟就好了,一直接近终点。肯定尽量先斜着走。while根据两者的位置分成好几种情况。根据ASCLL码,直接++,--就好了,不用再变成数字了。string s。s[0],s[1]直接++--就好了,直到等于e[0],e[1]。
使用一个tot来计数,此为总步数。
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
string map[];
string s,e;
int main()
{
int tot=;
cin>>s;
cin>>e;
while(s[]<e[]&&s[]<e[])
{
s[]++;s[]++;
map[tot++]="RU";
}
while(s[]<e[]&&s[]>e[])
{
s[]++;s[]--;
map[tot++]="RD";
}
while(s[]>e[]&&s[]<e[])
{
s[]--;s[]++;
map[tot++]="LU";
}
while(s[]>e[]&&s[]>e[])
{
s[]--;s[]--;
map[tot++]="LD";
}
while(s[]==e[]&&s[]>e[])
{
s[]--;
map[tot++]="D";
}
while(s[]==e[]&&s[]<e[])
{
s[]++;
map[tot++]="U";
}
while(s[]==e[]&&s[]<e[])
{
s[]++;
map[tot++]="R";
}
while(s[]==e[]&&s[]>e[])
{
s[]--;
map[tot++]="L";
}
cout<<tot<<endl;
for(int i=;i<tot;i++)
cout<<map[i]<<endl;
}

A - Shortest path of the king (棋盘)的更多相关文章

  1. Codeforces Beta Round #3 A. Shortest path of the king 水题

    A. Shortest path of the king 题目连接: http://www.codeforces.com/contest/3/problem/A Description The kin ...

  2. Codeforces-A. Shortest path of the king(简单bfs记录路径)

    A. Shortest path of the king time limit per test 1 second memory limit per test 64 megabytes input s ...

  3. 3A. Shortest path of the king

    给你一个的棋盘, 问:从一个坐标到达另一个坐标需要多少步? 每次移动可以是八个方向.   #include <iostream> #include <cmath> #inclu ...

  4. Codeforces Beta Round #3 A. Shortest path of the king

    标题效果: 鉴于国际棋盘两点,寻求同意的操作,是什么操作的最小数量,在操作过程中输出. 解题思路: 水题一个,见代码. 以下是代码: #include <set> #include < ...

  5. Shortest path of the king

    必须要抄袭一下这个代码 The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose h ...

  6. CF3A Shortest path of the king

    The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, becaus ...

  7. node搜索codeforces 3A - Shortest path of the king

    发一下牢骚和主题无关: 搜索,最短路都可以     每日一道理 人生是洁白的画纸,我们每个人就是手握各色笔的画师:人生也是一条看不到尽头的长路,我们每个人则是人生道路的远足者:人生还像是一块神奇的土地 ...

  8. CF3A 【Shortest path of the king】

    一句话题意:在8 * 8的棋盘上,输出用最少步数从起点走到终点的方案 数据很小,可以广搜无脑解决 定义数据结构体 struct pos{ int x,y,s; //x.y表示横纵坐标,s表示步数 ]; ...

  9. Codeforces 3A-Shortest path of the king(BFS打印路径)

    A. Shortest path of the king time limit per test 1 second memory limit per test 64 megabytes input s ...

随机推荐

  1. POJ 2796:Feel Good 单调栈经典题

    Feel Good Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 11626   Accepted: 3212 Case T ...

  2. cf 500 D. New Year Santa Network

    直接按边分,2个点在边的一边,1个在另一边,组合出来就是这个边对答案的贡献,权值换了就再重新算个数而已. #include <bits/stdc++.h> #define LL long ...

  3. 怎么更改Rstudio中的默认目录

    方法一. 每次启动Rstudio之后,执行代码 setwd("F:/R/R_data") 默认目录就会修改为双引号内的位置路径. 方法二. 对Rstudio进行设置一次即可. ①点 ...

  4. 2-Java基本数据类型和运算符

    目录 Java基本类型 Java数据类型转换 Java运算符 1.Java基本类型 1.1.boolean布尔 - 只有true和false两种值,在内存中占1bits(位),默认是false 1.2 ...

  5. 实验吧-隐写术-黑与白(二)(反转+五笔+Image steganography)

    反转有二:颜色反转.文件名反转 文件名这么乱,毫无规律,好奇怪,进行反转后发现是:steganography(就是隐写术的意思),这还是个图片文件,有一款工具正好叫Image steganograph ...

  6. “战疫”需求不再等-京东云与AI【应急资源信息发布平台】召集开发者共同支援

    截止北京时间 2020年2月5日19时00分,全国确诊新型冠状病毒肺炎24423例,疑似23260例. 新年伊始,一切都显得和往年有那么一点不一样.疫情牵动着每一个人的心脏,也有很多人早就放弃了假期投 ...

  7. 本地的jar包导入到maven仓库

    需要引入本地jar,然后百度跟着教程实现了,做个记录加深印象.https://www.cnblogs.com/lixuwu/p/5855031.html 1首先找到要传入maven的jar包(放在一个 ...

  8. exctern C

    在C++中调用C语言 因为C++扩展了函数重载.编译时会将函数名修改,所以直接条用会出错. #ifdef __cplusplusextern "C" {#endif // __cp ...

  9. VM虚拟机安装 常用Linux命令 网卡配置 (第二天)

    VM虚拟机安装:(昨天已经安装好了VM了,按照提示安装就好,很简单) 1.安装centos7虚拟机,现在磁盘里面新建文件夹作为安装文件夹 2.找到centos7的iso文件,打开vm-新建虚拟机-按照 ...

  10. Kubernetes-基于helm安装部署高可用的Redis及其形态探索(二)

    上一章,我们通过实践和其他文章的帮助,在k8s的环境安装了redis-ha,并且对其进行了一些实验来验证他的主从切换是否有效.本篇中将会分析,究竟是如何实现了redis-ha的主从切换,以及其与K8S ...