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 ...
随机推荐
- Oracle运算符收录(易忘记,但是又很重要的运算符)
Create Table Test6( id ), name ), age ), sex ) ) 1. || 符 字符串连接字符串,注意:文字和日期一定嵌入在单引号里面 select ID,Nam ...
- JavaScript HTML DOM学习记录
HTML DOM (文档对象模型) 当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model). HTML DOM 模型被构造为对象的树. HTML DOM 树 通过 ...
- C指针总结
取内容* 从右至左 取地址& 从右至左 同类型指针变量关系运算是有意义的. 指针变量和数组名都表示数组的地址,但是数组名是地址常量. *p++和(*p)++不同.*p++的赋值结果跟*p相同, ...
- Codeforces 936E. Iqea
Description 给出一张四连通网格图,其中有 \(n\) 个点是连通的,维护以下两种操作: 1.把某个点变黑 2.给出一个白点,查询离这个白点最近的黑点的距离 题面 Solution 我们把每 ...
- Laravel 使用Voyager导致多个数据库连接总是返回默认连接?
问题与分析 最近的项目碰到一个奇怪的问题,在Laravel(5.3)中想建立多个数据库连接连到MySQL的不同数据库(另一个连接名为conn2),执行如下语句得到却发现得到的仍然是默认连接: $con ...
- hexo+github搭建博客跳坑
hexo+GitHub搭建博客过程中,hexo安装成功,可以启动和运行,但是访问localhost:4000却无法访问,弄了半天,最后发现是福昕阅读器占用了4000端口 解决办法: 采用命令hexo ...
- Java - 关于扩展线程安全类的一些思考
重用可以节省我们进行开发和测试(测试比我们自己测严谨地多)的时间和其他各种成本. 但是,对一个线程安全类进行扩展的时候就需要思考一些问题. 比如我们熟知的线程安全类Vector,该类中对所有的公有方法 ...
- SSH框架整合中Hibernate实现Dao层常用结构
一.疑惑 一直以来,我在使用SSH框架的时候经常会发现后者有疑虑到底使用hibernate的那种方法或者如何配置hibernate来操作数据库,经过 一段时间的学习下面我来总结一下,常用的dao层配置 ...
- Springboot简单整合Rabbit
两个项目.分别是生产者和消费者项目 .首先引入依赖.两边pom都一样 第一次练习,启动生产者后,再启动消费者,一直报找不到 队列的声明. 后排查发现是 需要现在生产者这边浏览器访问一次生产消息的方法 ...
- 互联网轻量级框架SSM-查缺补漏第七天(MyBatis的解析和运行原理)
第七章MyBatis的解析和运行原理 SqlSessionFactory是MyBatis的核心类之一,其最重要的功能就是提供创建MyBatis的核心借口SqlSession,所以要先创建SqlSess ...