Codeforces Round #342 (Div. 2) B. War of the Corporations 贪心
B. War of the Corporations
题目连接:
http://www.codeforces.com/contest/625/problem/B
Description
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.
This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineapple did their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of the new artificial intelligence is similar to the name of the phone, that Pineapple released 200 years ago. As all rights on its name belong to Pineapple, they stand on changing the name of Gogol's artificial intelligence.
Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of technology was already printed on all devices, the Gogol's director decided to replace some characters in AI name with "#". As this operation is pretty expensive, you should find the minimum number of characters to replace with "#", such that the name of AI doesn't contain the name of the phone as a substring.
Substring is a continuous subsequence of a string.
Input
The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100 000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters.
Output
Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring.
Sample Input
intellect
tell
Sample Output
1
Hint
题意
给你s1 s2,你每次操作可以使得s1串中某个字符变成#,然后问你最小修改多少次,就可以使得s1中不含有s2子串
题解:
贪心,我们每次修改最后一个字符就好了
这样相交的一定都被修改了
代码
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
int main()
{
cin>>s1>>s2;
int ans = 0;
for(int i=0;i<s1.size();i++)
{
int flag = 0;
for(int j=0;j<s2.size();j++)
{
if(i+j>s1.size())
{
flag = 1;
break;
}
if(s1[i+j]!=s2[j])
{
flag = 1;
break;
}
}
if(flag==0)
{
s1[i+s2.size()-1]='#';
ans++;
}
}
cout<<ans<<endl;
}
Codeforces Round #342 (Div. 2) B. War of the Corporations 贪心的更多相关文章
- Codeforces Round #342 (Div. 2) B. War of the Corporations(贪心)
传送门 Description A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Go ...
- Codeforces Round #342 (Div. 2)-B. War of the Corporations
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces Round #342 (Div. 2)
贪心 A - Guest From the Past 先买塑料和先买玻璃两者取最大值 #include <bits/stdc++.h> typedef long long ll; int ...
- Codeforces Round #342 (Div. 2) B
B. War of the Corporations time limit per test 1 second memory limit per test 256 megabytes input st ...
- Codeforces Round #342 (Div. 2) D. Finals in arithmetic 贪心
D. Finals in arithmetic 题目连接: http://www.codeforces.com/contest/625/problem/D Description Vitya is s ...
- Codeforces Round #342 (Div. 2) C. K-special Tables 构造
C. K-special Tables 题目连接: http://www.codeforces.com/contest/625/problem/C Description People do many ...
- Codeforces Round #342 (Div. 2) A - Guest From the Past 数学
A. Guest From the Past 题目连接: http://www.codeforces.com/contest/625/problem/A Description Kolya Geras ...
- Codeforces Round #342 (Div. 2) E. Frog Fights set 模拟
E. Frog Fights 题目连接: http://www.codeforces.com/contest/625/problem/E Description stap Bender recentl ...
- Codeforces Round #342 (Div. 2) D. Finals in arithmetic(想法题/构造题)
传送门 Description Vitya is studying in the third grade. During the last math lesson all the pupils wro ...
随机推荐
- EditText 光标不显示问题
android:textCursorDrawable="@drawable/bg_txt_cursor" <?xml version="1.0" enco ...
- asp.net下ajax.ajaxMethod使用方法(转)
使用AjaxMethod可以在客户端异步调用服务端方法,简单地说就是在JS里调用后台.cs文件里的方法,做一些JS无法做到的操作,如查询数据库 使用AjaxMethod要满足一下几点: 1.如 ...
- centos7虚拟机无法上网的解决办法
今天在VMware虚拟机中经过千辛万苦终于安装好了centos7..正兴致勃勃的例行yum update 却发现centos系统貌似默认网卡没配置好,反馈无法联网.经过一番研究,终于让centos连上 ...
- 使用json格式的数据进行通信
4 Java对象转换成JSON 4.1 问题 将Java对象转换成符合JSON格式的字符串,并测试. 4.2 方案 使用与json-lib.jar相关的jar文件完成类型的转换. 4.3 步骤 步骤一 ...
- Java核心 --- 枚举
Java核心 --- 枚举 枚举把显示的变量与逻辑的数字绑定在一起在编译的时候,就会发现数据不合法也起到了使程序更加易读,规范代码的作用 一.用普通类的方式实现枚举 新建一个终态类Season,把构造 ...
- RequiredFieldValidator的使用
特別說明:1.一個Button要對頁面的多個控件進行驗證,則需要設置button和其它受控控件的ValidationGroup屬性 aspx頁面實例: <tr class="h&quo ...
- [转] js prototype详解
JavaScript能够实现的面向对象的特征有:·公有属性(public field)·公有方法(public Method)·私有属性(private field)·私有方法(private fie ...
- Linux系统github使用
命令行下使用: 1.检查ssh key cd ~/.ssh 如果提示"No such file or directory",则需要创建一个ssh key. 2.创建ssh key. ...
- 在RHEL5.4下安装ORACLE11G
以root身份登录到系统,新增组和用户: #groupadd oinstall #groupadd dba #useradd -g oinstall -G dba oracle #passwd ora ...
- MYSQL数据库重点:自定义函数、存储过程、触发器、事件、视图
一.自定义函数 mysql自定义函数就是实现程序员需要sql逻辑处理,参数是IN参数,含有RETURNS字句用来指定函数的返回类型,而且函数体必须包含一个RETURN value语句. 语法: 创建: ...