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. Quartz.NET 实现定时任务调度

    Quartz.NET Quick Start Guide Welcome to the Quick Start Guide for Quartz.NET. As you read this guide ...

  2. Memcached管理与监控

    一个用PHP编写的可视化的MemCached管理系统 MemAdmin是一款可视化的Memcached管理与监控工具,使用PHP开发,体积小,操作简单. 主要功能: 服务器参数监控:STATS.SET ...

  3. PHP系统学习2

    字符串操作 字符串截取 substr() 字符串格式化printf()格式化无需echo sprintf() 需要echo nl2br()可以将\n转换成<br/> wordwrap() ...

  4. git commit 、CHANGELOG 和版本发布的标准自动化

    一直以来,因为团队项目迭代节奏很快,每次发布的更新日志和版本更新都是通过人肉来完成的.有时候实在忙的团团转,对于手动的写这些更新信息就显得力不从心了.对于团队新来的小伙伴,有时候遇到些紧急情况,就更显 ...

  5. log4j 具体解说(不能再具体了)

    日志是应用软件中必不可少的部分.Apache的开源项目log4j是一个功能强大的日志组件,提供方便的日志记录.在apache站点:jakarta.apache.org/log4j 能够免费下载到Log ...

  6. KVC之-setValue:forKey:方法实现原理与验证

    KVC之-setValue:forKey:方法实现原理与验证 - (void)setValue:(id)value forKey:(NSString *)key方法,实现原理与验证 功能:使用一个字符 ...

  7. freemarker和jsp的比较

    1.共享变量 FreeMarker 的共享变量是我最喜欢的“隐藏”功能之一.此功能可以让你设置自动添加到所有模板的值. 例如,可以设置应用程序的名称作为共享变量. 1 2 Configuration ...

  8. 跟着百度学PHP[15]-会话控制session的工作机制

    COOKIE和SESSION的两大区别: cookie是存储与客户端 session是存储与服务端 需要开启session的时候需要使用session_start开启,且session的开头不能拥有任 ...

  9. [Python]计算闰年时候出现的and和or优先级的问题以及短路逻辑

    好吧题目非常easy.可是有些细节还是挺有意思的. 题目是:计算今年是否是闰年,推断闰年条件,满足年份模400为0,或者模4为0可是模100不为0 答案是这种: import time #计算今年是否 ...

  10. C++读取Sql Server

    代码如下: // ReadSqlConsole.cpp: 主项目文件. #include "stdafx.h" #include <iostream> #include ...