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 ...
随机推荐
- 第五章:Javascript语句
在javascript中,表达式是短语,那么语句(statement)就是整句或命令.正如英文语句以句号结尾,javascript以分号结尾. 表达式计算出一个值,但语句使某件事发生. “使某件事发生 ...
- php empty()和isset()的区别
在使用 php 编写页面程序时,我经常使用变量处理函数判断 php 页面尾部参数的某个变量值是否为空,开始的时候我习惯了使用 empty() 函数,却发现了一些问题,因此改用 isset() 函数,问 ...
- oracle练习题
题干:设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher). 建表后数据如下: SQL> select * from ...
- poj1056 (Trie入门)寻找字符串前缀
题意:给你一堆字符串,问是否满足对于任意两个字符串a.b,a不是b的前缀 字典树==前缀树==Trie树 trie入门题,只用到了insert和query操作 #include <cstdio& ...
- 洛谷P1121 环状最大两段子段和
题目描述 给出一段环状序列,即认为A[1]和A[N]是相邻的,选出其中连续不重叠且非空的两段使得这两段和最大. 输入输出格式 输入格式: 输入文件maxsum2.in的第一行是一个正整数N,表示了序列 ...
- POJ 2559 Largest Rectangle in a Histogram
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18942 Accepted: 6083 Description A hi ...
- 一个cheat命令 == Linux命令小抄大全
本文介绍一个Linux超级命令,有了这个命令,你就可以开开心心的使用linux上的各种命令了.当你要执行一个linux命令,在这个命令参数选项众多时,你一般怎么做?对,我们大多数人都会去求助man命令 ...
- CSS------添加注释框
my.html <div><a href="#" class="tip">你好<span><k>哈哈哈哈< ...
- iOS Xcode 调试技巧 全局断点这样加才有意思
http://blog.sina.com.cn/s/blog_876a2c9901016ezh.html
- varnish4.0简介
Varnish 4.0 简介 Varnish 是一款开源的HTTP加速器和反向代理服务器,它的主要特点有: (1)是基于内存缓存,重启后数据将消失.(2)利用虚拟内存方式,io性能好.(3)支持设置0 ...