#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
char str1[],str2[];
bool vis[];
int main(){ while(scanf("%s",str1)!=EOF){
getchar();
memset(str2,,sizeof(str2));
memset(vis,false,sizeof(vis));
scanf("%s",str2);
getchar();
int len1=strlen(str1);
int len2=strlen(str2);
int flag=;
int len;
if(len1>len2){
flag=;
len=len1-len2;
}
else if(len1==len2){
flag=;
len=;
}
else if(len1<len2){
flag=;
len=len2-len1;
}
int End=;
int temp;
for(int i=len2-;i>=;i--){
temp=;
for(int j=;j<len1;j++){
if(str2[i]==str1[j]&&!vis[j]){
End++;
vis[j]=true;
temp=;
break;
}
}
if(temp==)
break;
} if(flag==){
for(int i=;i<len;i++){
printf("d\n");
}
for(int i=;i<len2;i++){
printf("m %c\n",str2[i]);
} } else if(flag==){
for(int i=;i<len2;i++)
printf("m %c\n",str2[i]); } else if(flag==){
for(int i=;i<len;i++){
printf("a %c\n",str2[i]);
}
for(int i=len;i<len2;i++){
printf("m %c\n",str2[i]);
} }
memset(str1,,sizeof(str1));
}
return ;
}
E - Edit distance

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

Given a string, an edit script is a set of instructions to turn it into another string. There are
four kinds of instructions in an edit script:

Add (‘a’): Output one character. This instruction does not consume any characters
from the source string.

Delete (‘d’): Delete one character. That is, consume one character from the source string and output nothing.

Modify (‘m’): Modify one character. That is, consume one character from the source string and output a character.

Copy (‘c’): Copy one character. That is, consume one character from the source string and output the same character.

Now, We define that A shortest edit script is an edit script that minimizes the total number of adds and deletes.

Given two strings, generate a shortest edit script that changes the first into the second.

 

Input

The input consists of two strings on separate lines. The strings contain only alphanumeric
characters. Each string has length between 1 and 10000, inclusive.
 

Output

The output is a shortest edit script. Each line is one instruction,
given by the one-letter code of the instruction (a, d, m, or c),
followed by a space, followed by the character written (or deleted if
the instruction is a deletion).

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
 

HDU 2895 编辑距离的更多相关文章

  1. HDU 2895 贪心 还是 大水题

    DESCRIPTION:大意是给你两个字符串.编辑距离只有add和delete会产生.所以.编辑距离最短一定是两个字符串的长度差.然后...呵呵呵呵.... 猜题意就可以了...但是...我觉得这个题 ...

  2. hdu 2895 01背包 Robberies

    Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  3. HDU 4323 Magic Number(编辑距离DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=4323 题意: 给出n个串和m次询问,每个询问给出一个串和改变次数上限,在不超过这个上限的情况下,n个串中有多少个 ...

  4. HDU 4323——Magic Number——————【dp求编辑距离】2012——MUT——3

    Magic Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  5. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  6. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  7. 2012年长春网络赛(hdu命题)

    为迎接9月14号hdu命题的长春网络赛 ACM弱校的弱菜,苦逼的在机房(感谢有你)呻吟几声: 1.对于本次网络赛,本校一共6名正式队员,训练靠的是完全的自主学习意识 2.对于网络赛的群殴模式,想竞争现 ...

  8. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. [LeetCode] One Edit Distance 一个编辑距离

    Given two strings S and T, determine if they are both one edit distance apart. 这道题是之前那道Edit Distance ...

随机推荐

  1. 15.C#回顾及匿名类型(八章8.1-8.5)

    今天的篇幅应该会很长,除了回顾前面学的一些,还有写一些关于匿名类型的相关知识,总体上对后续的学习很有帮助,学好了,后面更容易理解,不明白的,那就前面多翻几次,看多了总是会理解的.那么,进入正题吧. 自 ...

  2. C#基础知识系列七(base、this、new、override、abstract、virtual、static)

    前言 本文主要来讲解一下C#中,自己觉得掌握的不怎么样或者用的不多,不太熟悉的关键字,主要包括base.this.new.override.abstract.virtual以及针对static字段和s ...

  3. AngularJS——karma的安装

    1,前言: 刚刚学过了 grunt的安装以及使用,grunt的作用就是让我们平常不想做的任务能够自动化完成,并且可以自己 自定义任务,那么karma是什么呢? Karma是Testcular的新名字, ...

  4. Spring-如何实现事物管理的

    事务的实现方式 实现方式共有两种:编码方式:声明式事务管理方式.基于AOP技术实现的声明式事务管理,实质就是:在方法执行前后进行拦截,然后在目标方法开始之前创建并加入事务,执行完目标方法后根据执行情况 ...

  5. 【UVA 1586】Ancient Cipher

    题 题意 给你一个只含CHON的有机物的化学式如C6H5OH求相对分子质量 分析 ... 代码 switch #include<cstdio> #include<cctype> ...

  6. 【CodeForces 618B】Guess the Permutation

    题 题意 有个1到n的一个全排列,告诉你第i个数和全部n个数相比的较小的是哪个,和自己相比时为0,于是有个主对角线为0的矩阵,求原数列 分析 我的想法是,给我们的每一行之和按大小排一下,就知道第i个数 ...

  7. Hive 正则匹配函数 regexp_extract

    regexp_extract 语法:    regexp_extract(string subject,  string pattern,  int index) 返回值: string 说明:  将 ...

  8. hdu 2199 Can you solve this equation?

    #include<stdio.h> #include<math.h> double f(double x) { return 8*x*x*x*x+7*x*x*x+2*x*x+3 ...

  9. JS面试题及答案总结

    1. 截取字符串abcdefg的efg  <div id="test">abcdefg</div> var mytext=document.getEleme ...

  10. JS 下拉菜单

    HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <titl ...