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 ...
随机推荐
- python中 datetime模块的详解(转载)
Python提供了多个内置模块用于操作日期时间,像calendar,time,datetime.time模块我在之前的文章已经有所介绍,它提供 的接口与C标准库time.h基本一致.相比于time模块 ...
- LR自我总结的问题
1.Controller中添加负载测试时,最后运行完提示the following graph s were not created.导致最后没有数据报表生成. 解决方法:在result中将auto ...
- MySQL查询近一个月的数据
MySQL查询近一个月的数据 近一个月统计SQL select user_id, user_name, createtime from t_user where DATE_SUB(CURDATE(), ...
- Xcode插件路径、缓存路径、图片压缩工具路径、代码片段路径、symbolicatecrash路径
Xcode插件路径 ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins Xcode缓存路径 ~/Library/Devel ...
- 正排索引(forward index)与倒排索引(inverted index)
正常的索引一般是指关系型数据库里的索引. 把不同的数据存放到不同的字段中.如果要实现baidu或google那种搜索,就需要与一条记录的多个字段进行比对,需要 全表扫描,如果数据量比较大的话,性能就很 ...
- Redis - 数据类型常用命令
5种数据类型都离不开key,先列出key的相关命令. KEY相关操作 列出符合规则的KEYS KEYS pattern pattern支持glob风格的通配符格式,即: ? 一个字符 * 任意多个字符 ...
- .NET的EF框架中:在应用程序配置文件中找不到名为“”的连接字符串问题
今天在使用EF Code First框架时,当把模型都定义好了,想通过程序包管理控制台利用enable-migrations –force来生成数据库表的时候报错了,如下: 找不到连接字符串,但是我仔 ...
- java 的底层通信--Socket
以前一直不太重视java 基础的整理,感觉在实际开发中好像java 基础用处不大,感觉不理解一些底层的东西对开发工作影响也不大.不过,后来我发现,很多东西都是相互联系的,如果底层的东西你不理解,后面的 ...
- 关于sql优化整理一下
1.where 子句中可以对字段进行 null 值判断吗? 可以,比如 select id from t where num is null 这样的 sql 也是可以的.但是最好不要给数 ...
- javaweb之jsp标签
1.JSP标签简介 JSP标签也称之为Jsp Action(JSP动作)元素,它用于在Jsp页面中提供业务逻辑功能,避免在JSP页面中直接编写java代码,造成jsp页面难以维护. 2.JSP常用标签 ...