【日常训练】Hockey(CodeForces-96C)

题意与分析

对于这题题意的理解比较重要,因为这是一条傻逼题:

  • 大小写保持不变
  • 原串中出现的非法字符串里的每一个字符都要替换
  • Lucky Letter越多越好

这样一种情况下,算法其实特别简单。我傻逼在一个地方:暴力的时候一定要考虑所有的非法串,不能看到一个匹配了就走了(举例: IjksdfIj)。

代码

 1 /*
 2  * Code name => training-190315-c.cc
 3  * Written by Sam X
 4  * Date: 三月, 15, 2019
 5  * Time: 16:33
 6  */
 7 #include <bits/stdc++.h>
 8 #define fi first
 9 #define se second
10 #define MP make_pair
11 #define MS(x,y) memset(x, y, sizeof(x))
12 #define ZERO(x) memset(x, 0, sizeof(x))
13 #define rep(i,a,b)    for(repType i=static_cast<repType>(a); \
14                         i<=static_cast<repType>(b);++i)
15 #define per(i,a,b)    for(repType i=static_cast<repType>(a); \
16                         i>=static_cast<repType>(b);--i)
17 #define ALL(x) x.begin(), x.end()
18 
19 using namespace std;
20 using repType=signed;
21 using ll=long long;
22 using ld=long double;
23 using pi=pair<int,int>;
24 string w,w_s; 
25 
26 void chg(int i, char chr)
27 {
28     if(isupper(w[i]))
29     {
30         w[i]=toupper(chr);
31     }
32     else w[i]=tolower(chr);
33 }
34 
35 signed main()
36 {
37 #ifdef DEBUG
38     freopen("input.txt", "r", stdin);
39     freopen("output.txt", "w", stdout);
40 #endif
41 
42     int n;
43     vector<string> vec;
44     vector<string> vec_s;
45     cin>>n; 
46     rep(i,1,n)
47     {
48         string tmp;
49         cin>>tmp;
50         vec.push_back(tmp);
51         transform(ALL(tmp), tmp.begin(), ::tolower);
52         vec_s.push_back(tmp);
53     }
54     char chr;
55     cin>>w>>chr;
56     w_s=w; transform(ALL(w_s), w_s.begin(), ::tolower);
57     int i=0;
58     while(i<int(w.size()))
59     {
60         rep(j,0,vec.size()-1)
61         {
62             if(i+vec[j].size()<=w.size() && w_s.substr(i,vec[j].size())==vec_s[j])
63             {
64                 //cout<<"find "<<vec[j]<<endl;
65                 for(int k=i; k!=i+vec[j].size(); ++k)
66                 {
67                     if(w_s[k]==tolower(chr))
68                     {
69                         if(chr!='a')
70                             chg(k, 'a');
71                         else
72                             chg(k, 'b');
73                     }
74                     else chg(k, chr);
75                 }
76                 // break; // nm$l 不应该break
77             }
78         }
79         i++;
80     }
81     cout<<w<<endl;
82     return 0;
83 }
点我看高清美少女

 

posted @ 2019-03-16 15:37  ISoLT  阅读(188)  评论(0编辑  收藏  举报