zoukankan      html  css  js  c++  java
  • 【日常训练】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 }
    点我看高清美少女
  • 相关阅读:
    MySQL系列(四)--数据库结构优化、范式化与反范式化
    Java数据结构和算法(二)--队列
    Java数据结构和算法(一)--栈
    MySQL系列(三)--MySQL存储引擎
    Java集合(六)--ArrayList、LinkedList和Vector对比
    Java集合(五)--LinkedList源码解读
    Java集合(四)--基于JDK1.8的ArrayList源码解读
    P1048 采药(洛谷,动态规划递推,01背包原题)
    P1091 合唱队形题解(洛谷,动态规划LIS,单调队列)
    语法摔过的坑(用来给自己看的,粗糙,勿点)
  • 原文地址:https://www.cnblogs.com/samhx/p/cf96c.html
Copyright © 2011-2022 走看看