思路

在字符串中不断做匹配 找到一个匹配就输出

时间复杂度\(O(n)\)

ps.模式串是定长的,因此看做常数

代码

#include<string>
#include<iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    string ch;
    cin >> ch;
    for (auto i = 0; i < n; i++) {
        if (ch.substr(i, 7) == "AlvinZH")
            cout << "hg, shg, awsl!\n";
        else if (ch.substr(i, 10) == "ModricWang")
            cout << "1080Ti!, wyr, silver!!!\n";
        else if (ch.substr(i, 6) == "Bamboo")
            cout << "this is 51's father\n";
        else if (ch.substr(i, 11) == "ConnorZhong")
            cout << "I am so weak\n";
        else if (ch.substr(i, 4) == "BCPC")
            cout << "I want to join in!\n";
    }
    return 0;
}

相关文章:

  • 2021-09-07
  • 2021-07-13
  • 2021-07-15
  • 2021-11-04
  • 2021-08-07
  • 2022-12-23
  • 2021-12-16
  • 2022-02-19
猜你喜欢
  • 2021-08-22
  • 2021-07-11
  • 2022-12-23
  • 2021-10-30
  • 2021-09-16
  • 2022-01-09
  • 2021-09-03
相关资源
相似解决方案