#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. jQuery使用之(一)标记元素属性

    jQuery使用主要介绍jQuery如何控制页面,包含元素的属性.css样式风格.DOM模型.表单元素和事件处理等. 标记元素的属性 html中每一个标记都具有一些属性,他们这个标记在页面中呈现各种状 ...

  2. easyui_动态添加隐藏toolbar按钮

    目标:动态添加隐藏toolbar,比如根据权限动态显示新增.修改.删除按钮等 思路:先初始化toolbar的所有按钮,加载datagrid其它信息,再根据权限显示隐藏toolbar按钮 步骤: 1.加 ...

  3. Java设计模式-桥接模式(Bridge)

    桥接模式就是把事物和其具体实现分开,使他们可以各自独立的变化.桥接的用意是:将抽象化与实现化解耦,使得二者可以独立变化,像我们常用的JDBC桥DriverManager一样,JDBC进行连接数据库的时 ...

  4. 消灭textarea中的神秘空格

    之前在做页面的时候经常发现写的textarea中会有一些默认的空格出现,鼠标可以在里面任意点击.这个问题折腾了好久,后来发现,原来是<textarea></textarea>标 ...

  5. BZOJ4590 自动刷题机

    Description 曾经发明了信号增幅仪的发明家SHTSC又公开了他的新发明:自动刷题机--一种可以自动AC题目的神秘装置.自动 刷题机刷题的方式非常简单:首先会瞬间得出题目的正确做法,然后开始写 ...

  6. Xcode 6以上版本如何创建一个空的工程(Empty Application)

    Xcode 6 正式版里面没有Empty Application这个模板,这对于习惯了纯代码编写UI界面的程序员来说很不习惯. 有高手给出了一个解决方法是,把Xcode 6 beta版里面的模板复制过 ...

  7. UVa 437 The Tower of Babylon

    Description   Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of ...

  8. DLUTOJ 1209 字典序和r-子集

    传送门 Time Limit: 6 Sec  Memory Limit: 128 MBSubmit: 73  Solved: 14 Description Input 多组输入数据. 每组数据: 第一 ...

  9. Linux内核之内存管理完全剖析

    linux虚拟内存管理功能 ? 大地址空间:? 进程保护:? 内存映射:? 公平的物理内存分配:? 共享虚拟内存.实现结构剖析   (1)内存映射模块(mmap):负责把磁盘文件的逻辑地址映射到虚拟地 ...

  10. NSThread - (void)start vs java Thread implements Runnable

    This method spawns the new thread and invokes the receiver’s main method on the new thread. If you i ...