ZeptoLab Code Rush A. King of Thieves

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.