1065 Beihang Collegiate Pronunciation Contest 2017
思路
在字符串中不断做匹配 找到一个匹配就输出
时间复杂度(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!
";
else if (ch.substr(i, 10) == "ModricWang")
cout << "1080Ti!, wyr, silver!!!
";
else if (ch.substr(i, 6) == "Bamboo")
cout << "this is 51's father
";
else if (ch.substr(i, 11) == "ConnorZhong")
cout << "I am so weak
";
else if (ch.substr(i, 4) == "BCPC")
cout << "I want to join in!
";
}
return 0;
}