HDU ACM 2895-Edit distance
Edit distance
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 39 Accepted Submission(s) : 17
Problem Description
Input
Output
In case of a tie, you must generate shortest edit script, and must sort in order of a , d, m, c. Therefore, there is only one answer.
Sample Input
abcde
xabzdey
Sample Output
a x
a a
m b
m z
m d
m e
m y
解题思路:
严格按照 a(增加),d(删除),m(改变),c(复制) 的改变顺序来输出,将第一个字符串转换成第二个字符串。如 abcde --> xabzdey, 增加(a)了x,a; 再逐个将abcde改变(m)成为bzdey。值得注意的是:如果两个字符对应相同,也不会用到copy,而要用m,如 abc --> abc ,用 m 的结果是 m a, m b, m c; 用 c 的结果是c a, c b, c d;但是遵循m在c之前(最简)原则,必须用m,其实就是没有要用c的时候,可以用c的地方,就一定可以用m来代替。

#include<stdio.h>
#include<string.h>
#define MAXN 10000
char s1[MAXN],s2[MAXN];
int main()
{
int n1,n2,n,i;
while(scanf("%s",s1)!=EOF)
{
scanf("%s",s2);
n1=strlen(s1);
n2=strlen(s2);
n=n2-n1;
if(n>)
{
for(i=;i<n2;i++)
{
if(n>)
{
printf("a %c\n",s2[i]);
n--;
}
else printf("m %c\n",s2[i]);
}
}
else if(n==)
{
for(i=;i<n2;i++)
printf("m %c\n",s2[i]);
}
else{
for(i=;i<n1;i++)
{
if(n<)
{
printf("d %c\n",s1[i]);
n++;
}
}
for(i=;i<n2;i++)
printf("m %c\n",s2[i]);
}
}
return ;
}
HDU ACM 2895-Edit distance的更多相关文章
- [LeetCode] One Edit Distance 一个编辑距离
Given two strings S and T, determine if they are both one edit distance apart. 这道题是之前那道Edit Distance ...
- [LeetCode] Edit Distance 编辑距离
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2 ...
- Edit Distance
Edit Distance Given two words word1 and word2, find the minimum number of steps required to convert ...
- 编辑距离——Edit Distance
编辑距离 在计算机科学中,编辑距离是一种量化两个字符串差异程度的方法,也就是计算从一个字符串转换成另外一个字符串所需要的最少操作步骤.不同的编辑距离中定义了不同操作的集合.比较常用的莱温斯坦距离(Le ...
- LintCode Edit Distance
LintCode Edit Distance Given two words word1 and word2, find the minimum number of steps required to ...
- stanford NLP学习笔记3:最小编辑距离(Minimum Edit Distance)
I. 最小编辑距离的定义 最小编辑距离旨在定义两个字符串之间的相似度(word similarity).定义相似度可以用于拼写纠错,计算生物学上的序列比对,机器翻译,信息提取,语音识别等. 编辑距离就 ...
- [UCSD白板题] Compute the Edit Distance Between Two Strings
Problem Introduction The edit distinct between two strings is the minimum number of insertions, dele ...
- hdu acm 1028 数字拆分Ignatius and the Princess III
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- 动态规划 求解 Minimum Edit Distance
http://blog.csdn.net/abcjennifer/article/details/7735272 自然语言处理(NLP)中,有一个基本问题就是求两个字符串的minimal Edit D ...
随机推荐
- (转)yum安装MariaDB(使用国内镜像快速安装,三分钟安装完毕)
原文:https://blog.csdn.net/p__csdn/article/details/72675840 https://tinpont.com/2017/fix-yum-download- ...
- Oracle PL/SQL编程之变量
注: 以下测试案例所用的表均来自与scott方案,使用前,请确保该用户解锁. 1.简介 和大多数编程语言一样,在编写PL/SQL程序时,可以定义常量和变量,在pl/sql程序中包括有: a.标量类型( ...
- Chrome Command API
Chrome Command API 参考 Chrome开发工具已经强大得令人发指了,除了可通过UI操作的各种功能外,还提供了基于控制台的命令行方法,极大地方便了开发调试.现在就来领略下Chrome ...
- JavaScript中变量声明以及数据类型
JavaScript变量 变量名必须以字母或下划线("_")开头 变量也能以 $ 和 _ 符号开头(不过我们不推荐这么做) 变量名称对大小写敏感(y 和 Y 是不同的变量) 变量可 ...
- JDK12 concurrenthashmap源码阅读
本文部分照片和代码分析来自文末参考资料 java8中的concurrenthashmap的方法逻辑和注解有些问题,建议看最新的JDK版本 建议阅读 concu ...
- docker 数据卷挂载总结
原文
- python2文件转换为exe可执行文件
windows下py文件的运行需要安装python,如果是exe文件就可以直接运行 1. 直接在命令行用pip安装 pyinstaller pip install pyinstaller 2 在命令行 ...
- 第一行代码 10.2使用HTTP协议访问网络 HttpURLConnection代码中的问题
实现HttpURLConnection代码的时候,遇到了问题. 怎样点击途中Send Request按钮,没有任何改变. 最后将MainActivity中的一段代码URL url = new URL( ...
- Redis(MySQL和redis怎么分工合作的?)
新手: redis也是服务器,主要部署在服务器上缓解服务器的压力,对于访问量交大的数据可以先缓存到redis,用户访问时直接访问redis,不用再直接访问数据库,缓解数据库的压力.mysql主要存储数 ...
- [转]JSON.parse()和JSON.stringify()
parse用于从一个字符串中解析出json对象,如 var str = '{"name":"huangxiaojian","age":&qu ...