1. Title Description: Click to open the link
2. Problem-solving ideas: The subject requirements in a string to find 5 equidistant ' * ', if any, output yes, otherwise output No. The idea is clear, first a long Len, and then raise the point I, to determine whether continuous uninterrupted jump 5 times and all are ' * '. The subject can also speed up the search, first look for the existence of ' * * * *, if there is, direct output yes.
3. Code:
#define _crt_secure_no_warnings #include <iostream> #include <algorithm> #include <string> #include <sstream> #include <set> #include <vector> #include <stack> #include <map> #include < queue> #include <deque> #include <cstdlib> #include <cstdio> #include <cstring> #include < cmath> #include <ctime> #include <functional>using namespace std;string s;int main () {//freopen ("T.txt", "R", stdin); int N;while (~SCANF ("%d", &n)) {cin >> s;int i;for (i = 0; i < n; i++) if (s[i] = = ' * ')//Find the first ' * ' bit Break;int cnt, OK = 0;if (Strstr (S.c_str (), "* * * *") = NULL) ok = 1;//acceleration measures else{for (int len = 1; len < n; len++)//Enumeration step {int cnt, k;for (int j = i; j < n-4 * Len, J + +)//lift point {cnt = 0, k = 0;while (K < 5) {if (s[j + k*len] = = ' * ') cnt++;e LSE break;k++;} if (cnt = = 5) {ok = 1; break;}}} if (OK) puts ("yes"), Else puts ("no");} return 0;}
ZeptoLab Code Rush A. King of Thieves