A. Message
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s.

String p is called a substring of string s if
you can read it starting from some position in the string s. For example, string "aba"
has six substrings: "a", "b", "a",
"ab", "ba", "aba".

Dr. Moriarty plans to take string s and cut out some substring from it, let's call it t.
Then he needs to change the substring t zero or more times. As a
result, he should obtain a fixed string u (which is the string that should be sent to Sherlock Holmes). One change is defined as making
one of the following actions:

  • Insert one letter to any end of the string.
  • Delete one letter from any end of the string.
  • Change one letter into any other one.

Moriarty is very smart and after he chooses some substring t, he always makes the minimal number of changes to obtain u.

Help Moriarty choose the best substring t from all substrings of the string s.
The substring t should minimize the number of changes Moriarty should make to obtain the string u from
it.

Input

The first line contains a non-empty string s, consisting of lowercase Latin letters. The second line contains a non-empty string u,
consisting of lowercase Latin letters. The lengths of both strings are in the range from 1 to 2000,
inclusive.

Output

Print the only integer — the minimum number of changes that Dr. Moriarty has to make with the string that you choose.

Examples
input
aaaaa
aaa
output
0
input
abcabc
bcd
output
1
input
abcdef
klmnopq
output

7

暴力

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h> using namespace std;
string a;
string b;
int main()
{
cin>>a>>b; int len1=a.length();
int len2=b.length();
int ans=10000000;
int len=len2;
if(len1<len2)
{
swap(a,b);
swap(len1,len2);
} for(int i=1;i<len2;i++)
{
int num=0;
for(int k=i,j=0;k<len2&&j<len1;k++,j++)
{
if(b[k]==a[j])
num++;
}
ans=min(ans,len-num);
} for(int i=0;i<len1;i++)
{
int num=0;
for(int k=i,j=0;j<len2&&k<len1;j++,k++)
{
if(a[k]==b[j])
num++;
} ans=min(ans,len-num);
}
printf("%d\n",ans); return 0;
}

CodeForces 156A Message(暴力)的更多相关文章

  1. Karen and Game CodeForces - 816C (暴力+构造)

    On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as fo ...

  2. Chladni Figure CodeForces - 1162D (暴力,真香啊~)

    Chladni Figure CodeForces - 1162D Inaka has a disc, the circumference of which is nn units. The circ ...

  3. Array and Segments (Easy version) CodeForces - 1108E1 (暴力枚举)

    The only difference between easy and hard versions is a number of elements in the array. You are giv ...

  4. CodeForces - 589D(暴力+模拟)

    题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...

  5. CodeForces - 589B(暴力)

    题目链接:http://codeforces.com/problemset/problem/589/B 题目大意:告诉你n 个矩形,知道矩形的长度和宽度(长和宽可以互换),每个矩形的长度可以剪掉一部分 ...

  6. CodeForces - 589B(暴力+排序)

    Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n ...

  7. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力

    题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum ...

  8. Codeforces 479B. Towers 暴力

    纯暴力..... B. Towers time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  9. Codeforces 129A-Cookies(暴力)

    A. Cookies time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

随机推荐

  1. C语言指针的易错点

    1.内存泄漏:申请的堆内存没有释放. 2.内存污染:前面非法操作使用内存(没有报错),后面写着写着就出错.如下代码: 当结构体中只有划线部分代码时,在编译器中编写不会报错,但此时已经造成非法操作内存, ...

  2. STM32关总中断的语句

    __set_PRIMASK();//关总中断 /************ **********/ __set_PRIMASK();//开总中断

  3. javascript和html中unicode编码和字符转义的详解

    1.html中的转义:在html中如果遇到转义字符(如“ ”),不管你的页面字符编码是utf-8亦或者是GB2312,都会直接打印成相应的字符:而当遇到(如:“\u8981”[此处的8981是16进制 ...

  4. unity, particle play once and destroy

    粒子播放一次后销毁:        //ref: http://answers.unity3d.com/questions/219609/auto-destroying-particle-system ...

  5. linux Apache CGI 安装配置

    Apache 中的提交了一种利用扩展应用程序执行动态网页的机制. 称为Common Gateway Interface (通用网关接口)简称CGI. 本文假定已安装好linux(本文的linux版本为 ...

  6. atitit.php 流行框架 前三甲为:Laravel、Phalcon、Symfony2 attilax 总结

    atitit.php 流行框架 前三甲为:Laravel.Phalcon.Symfony2 attilax 总结 1. ,最流行的PHP框架前三甲为:Laravel.Phalcon.Symfony2. ...

  7. LFCS 系列第八讲:管理用户和用户组、文件权限和属性以及启用账户 sudo 访问权限

    由于 Linux 是一个多用户的操作系统(允许多个用户通过不同主机或者终端访问一个独立系统),因此你需要知道如何才能有效地管理用户:如何添加.编辑.禁用和删除用户账户,并赋予他们足以完成自身任务的必要 ...

  8. 在Django中使用F()函数

    F()允许Django在未实际链接数据的情况下具有对数据库字段的值的引用.通常情况下我们在更新数据时需要先从数据库里将原数据取出后方在内存里,然后编辑某些属性,最后提交.例如这样 # Tintin f ...

  9. vim编码设置

    转载于:http://www.cnblogs.com/freewater/archive/2011/08/26/2154602.html vim 编码方式的设置和所有的流行文本编辑器一样,Vim 可以 ...

  10. mysql替换成指定字符

    ,,, ), 'XXXX' )-- 隐藏从第四位开始的6个字符,包括第四个字符,替换成X