zoukankan      html  css  js  c++  java
  • CF 1379 A. Acacius and String

    传送门

    题目:可以改变'?'为任意'a'~'z'的字符,可不可以让s有且仅有一个子串为"abacaba"。

    思路:暴力就行,枚举每个位置开始7个字符能否组成"abacaba",可以的话在判断此时把这7个位置的字符变成"abacaba"时,s有几个"abacaba"子串。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 #include <queue>
     5 #include <string>
     6 #include <vector>
     7 #include <cmath>
     8  
     9 using namespace std;
    10  
    11 #define ll long long
    12 #define pb push_back
    13 #define fi first
    14 #define se second
    15 
    16 const int N = 2e5 + 10;
    17 char s[N];
    18 int len;
    19 
    20 void solve()
    21 {      
    22     string p = "abacaba";
    23     int T;
    24     cin >> T;
    25     while(T--){
    26         string s, tmp;
    27         int n;
    28         cin >> n >> s;
    29 
    30         int good = 0;
    31         for(int i = 0; i < n; ++i){
    32             if(i + 6 >= n) break;
    33 
    34             //几个字符匹配
    35             int ok = 0;
    36             for(int j = 0; j < 7; ++j){
    37                 if(s[i + j] == '?' || p[j] == s[i + j]) ok++;
    38                 else break;
    39             }
    40             if(ok == 7){
    41                 tmp = s;
    42                 for(int j = 0; j < 7; ++j) tmp[i + j] = p[j];
    43 
    44                 //出现几次    
    45                 int cnt = 0;
    46                 string::size_type inx = 0;
    47                 while(1){
    48                     inx = tmp.find(p, inx);
    49                     //printf("inx = %d
    ", (int)inx);
    50                     if(inx == tmp.npos) break;
    51                     inx = inx + 3;
    52                     cnt++;
    53                 }
    54                 if(cnt == 1){
    55                     good = 1;
    56                     cout << "yes" << endl;
    57                     for(int j = 0; j < n; ++j){
    58                         cout << (tmp[j] == '?' ? 'z' : tmp[j]);
    59                     }
    60                     cout << endl;
    61                     break;
    62                 }
    63             }
    64         }
    65 
    66         if(!good) cout << "no" << endl;
    67     }
    68 }
    69  
    70 int main()
    71 {
    72     ios::sync_with_stdio(false);
    73     cin.tie(0);
    74     cout.tie(0); 
    75     solve();
    76  
    77     return 0;
    78 }
  • 相关阅读:
    MyEclipse Tern was unable to complete your request in time
    12.5.2 访问被覆盖的方法
    猎头、培训与咨询的价值(2)【补1】——北漂18年(93)
    12.5.1 通过 @ISA 继承
    从柯洁对战AlphaGo,看商业智能
    jquery ajax POST 例子详解
    利用组合索引优化
    Oracle range 分区表
    Perl 面向对象上
    JSON导出CSV中文乱码解决方案
  • 原文地址:https://www.cnblogs.com/SSummerZzz/p/13357178.html
Copyright © 2011-2022 走看看