HDU 2895 编辑距离
#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 ;
}
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
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
characters. Each string has length between 1 and 10000, inclusive.
Output
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
xabzdey
Sample Output
a a
m b
m z
m d
m e
m y
HDU 2895 编辑距离的更多相关文章
- HDU 2895 贪心 还是 大水题
DESCRIPTION:大意是给你两个字符串.编辑距离只有add和delete会产生.所以.编辑距离最短一定是两个字符串的长度差.然后...呵呵呵呵.... 猜题意就可以了...但是...我觉得这个题 ...
- hdu 2895 01背包 Robberies
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 4323 Magic Number(编辑距离DP)
http://acm.hdu.edu.cn/showproblem.php?pid=4323 题意: 给出n个串和m次询问,每个询问给出一个串和改变次数上限,在不超过这个上限的情况下,n个串中有多少个 ...
- 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 ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- 2012年长春网络赛(hdu命题)
为迎接9月14号hdu命题的长春网络赛 ACM弱校的弱菜,苦逼的在机房(感谢有你)呻吟几声: 1.对于本次网络赛,本校一共6名正式队员,训练靠的是完全的自主学习意识 2.对于网络赛的群殴模式,想竞争现 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- [LeetCode] One Edit Distance 一个编辑距离
Given two strings S and T, determine if they are both one edit distance apart. 这道题是之前那道Edit Distance ...
随机推荐
- use case
- new-nav-html
<header id="masthead" class="masthead" role="banner"> <h1 cla ...
- [转]Java中继承、多态、重载和重写介绍
什么是多态?它的实现机制是什么呢?重载和重写的区别在那里?这就是这一次我们要回顾的四个十分重要的概念:继承.多态.重载和重写. 继承(inheritance) 简单的说,继承就是在一个现有类型的基础上 ...
- xml文件的读写操作
1.直接上代码:包含了xml文档的创建,读取xml文档,创建根节点,向根节点中添加子节点,保存xml文档----------先来张效果图: static void Main(string[] args ...
- Ajax实现联动效果
用到了地区的数据库 html代码: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="s ...
- spring 第一篇(1-1):让java开发变得更简单(下)
切面(aspects)应用 DI能够让你的软件组件间保持松耦合,而面向切面编程(AOP)能够让你捕获到在整个应用中可重用的组件功能.在软件系统中,AOP通常被定义为提升关注点分离的一个技术.系统由很多 ...
- POJ3233 Matrix Power Series
Description Given a n × n matrix A and a positive integer k, find the sum S = A + A2 + A3 + … + Ak. ...
- Intel 80x86 Linux Kernel Interrupt(中断)、Interrupt Priority、Interrupt nesting、Prohibit Things Whthin CPU In The Interrupt Off State
目录 . 引言 . Linux 中断的概念 . 中断处理流程 . Linux 中断相关的源代码分析 . Linux 硬件中断 . Linux 软中断 . 中断优先级 . CPU在关中断状态下编程要注意 ...
- mybatis-spring从1.1升级到1.2所带来的dao层级的编写问题
我们公司的项目使用spring+mybatis组合.所以就必须得使用mybatis-spring了.所以此处就昨日mybatis-spring从1.1升级到1.2所带来的dao层级的编写问题,做了一个 ...
- jQuery EasyUI API 中文文档
http://www.cnblogs.com/Philoo/tag/jQuery/ 共2页: 1 2 下一页 jQuery EasyUI API 中文文档 - 树表格(TreeGrid) 风流涕淌 ...