Skip to main content
  1. Posts/

codeforces #342 div 2 B. War of the Corporations

·1 min
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

http://codeforces.com/contest/625/problem/B 题意:给出两个字符串,问要替换掉多少个字符才能使得前者中不包含后者。 思路:直接搞…找到一个把收尾替换成‘#’,然后下次从该位置继续开始找,直到找不到。

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年02月07日 星期日 17时31分33秒
 4File Name :code/cf/#342/B.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33string ori,tar;
34int main()
35{
36	#ifndef  ONLINE_JUDGE
37	freopen("code/in.txt","r",stdin);
38  #endif
39	cin>>ori>>tar;
40	int p = ori.find(tar);
41	int ans = 0 ;
42	int lst = 0;
43	while (p!=-1)
44	{
45	    ans++;
46	    ori[p]='#';
47	    lst = p + tar.length()-1;
48	    ori[lst]='#';
49
50	    p = ori.find(tar,lst);
51	}
52	cout<<ans<<endl;
53
54  #ifndef ONLINE_JUDGE
55  fclose(stdin);
56  #endif
57    return 0;
58}

Related

uva 10785 The Mad Numerologist

·2 mins
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid;=8&page;=show_problem&problem;=1726 题意:给出26个大写字母的权值,要求构造一个长度为n(n不超过210)的字符串。并且满足奇数位置只能放元音字母,偶数位置只能放辅音字母,且每个元音字母最多放21次,每个辅音字母最多放5次,要求构造的字符串的权值之和最小,在权值最小的前提下字典序最小。

uva 10194 Football (aka Soccer)

·2 mins
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid;=8&page;=show_problem&problem;=1135 题意:给出球队的名字和比赛的信息,得出stanging 思路:字符串处理。需要注意的是多组数据记得初始化多次,以及比较字典序的时候team name是大小写补敏感的。

uva 156 - Ananagrams

·2 mins
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=92 题意:给出一段文字,包含若干个单词,以’#‘结束。按照字典序输出所有的ananagrams。所谓ananagram,是指经过任意的重排后,不能得到这段文字中的另一个单词(不区分大小写) 思路:首先是字符串的读入…可以整行读入然后用空格分隔单词。由于补区分大小写,所以要都转化成小写…但是输出的时候要输出原始,所以还记得保留一份。而且要能够通过新的找到原始的(我用了一个toori的map<string,string>来实现) 然后最关键的部分是如何判断两个单词经过重排是否能一样…

uva 409 - Excuses, Excuses!

·2 mins
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid;=8&page;=show_problem&problem;=350 题意:给出k个key word,e个借口…找出包含key word最多的借口,即为最坏的借口。匹配补区分大小写&&同一个key word算多次。 思路:需要注意的是因为不区分大小写,需要都转化成大写或者小写。。但是输出的时候要输出原始的。。所以要另外存一份。

hdu 5611 || BC #69 div2 1002 Baby Ming and phone number

·2 mins
http://acm.hdu.edu.cn/showproblem.php?pid=5611 题意:给出n个电话号码(长度为11的字符串),满足特殊条件的价格为a,否则为b.特殊条件为最后5位数字一样,最后5位严格递增或者严格递减,最后8位是一个1980年1月一日到2016年12月31日的合法日期。问最后的价值。