Codeforces Round #342 (Div. 2) 625B War of the Corporations(stl)
2016-02-13 10:25
537 查看
B. War of the Corporations
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 test(s)
input
output
input
output
input
output
Note
In the first sample AI's name may be replaced with "int#llect".
In the second sample Gogol can just keep things as they are.
In the third sample one of the new possible names of AI may be "s#ris#ri".
题目链接:点击打开链接
给出两个字符串, 问至少修改a中几个字符, 可以使得a中没有子串与b相等.
使用stl string中substr()函数直接得到a的子串, 如果与b相等, 则标记当前子串的最后一个字符为'#', 同时计数.
AC代码:
#include "algorithm"
#include "queue"
#include "stack"
#include "cmath"
#include "utility"
#include "map"
#include "set"
#include "vector"
#include "list"
#include "string"
#include "cstdlib"
using namespace std;
typedef long long ll;
#define X first
#define Y second
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
string a, b;
int ans;
int main(int argc, char const *argv[])
{
cin >> a >> b;
int len1 = a.size(), len2 = b.size();
for(int i = 0; i < len1 - len2 + 1; ++i) {
string x = a.substr(i, len2);
if(x == b) {
ans++;
a[i + len2 - 1] = '#';
}
}
cout << ans << endl;
return 0;
}
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 test(s)
input
intellect tell
output
1
input
google apple
output
0
input
sirisiri sir
output
2
Note
In the first sample AI's name may be replaced with "int#llect".
In the second sample Gogol can just keep things as they are.
In the third sample one of the new possible names of AI may be "s#ris#ri".
题目链接:点击打开链接
给出两个字符串, 问至少修改a中几个字符, 可以使得a中没有子串与b相等.
使用stl string中substr()函数直接得到a的子串, 如果与b相等, 则标记当前子串的最后一个字符为'#', 同时计数.
AC代码:
#include "algorithm"
#include "queue"
#include "stack"
#include "cmath"
#include "utility"
#include "map"
#include "set"
#include "vector"
#include "list"
#include "string"
#include "cstdlib"
using namespace std;
typedef long long ll;
#define X first
#define Y second
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
string a, b;
int ans;
int main(int argc, char const *argv[])
{
cin >> a >> b;
int len1 = a.size(), len2 = b.size();
for(int i = 0; i < len1 - len2 + 1; ++i) {
string x = a.substr(i, len2);
if(x == b) {
ans++;
a[i + len2 - 1] = '#';
}
}
cout << ans << endl;
return 0;
}
相关文章推荐
- 例题:数据统计
- android web view
- ansys 15 for linux 安装纪录
- xp系统的 1607:无法安装 installshield scripting runtime
- ActionBar之属性详解总结(一)
- hdoj2027 统计元音
- MySQL的SQL_NO_CACHE
- C++拷贝构造函数详解
- ExcelParser ,Excel解析的工具类(正对解析xlsx)
- 关于vmnet1~vmnet8(虚拟机下的linxu网络连接方式)
- php等比例缩放图片及剪切图片代码分享
- 定位kernel32.dll
- LeetCode -- Power of Three
- [LeetCode]142. Linked List Cycle II
- C++构造函数与析构函数
- 上传文件2.0--drp203
- play-framework的安装与使用
- 数据结构实验之链表七:单链表中重复元素的删除
- iOS-基础动画
- 第十章泛型算法