Contest: Codeforces Round #300, problem: (A) Cutting Banner,
At the beginning, I was wrong about the meaning of the question. I thought it was just a casual deletion, as long as I could combine the rest in order to form CODEFORCES. Then I knew that I could only cut a segment.
All that we can manage to do is to cut out some substring from the banner, I. e. several consecutive letters.
Some here is a certain meaning, because the following substring does not add s .......
If the beginning or the end of the original banner was cut out, only one part remains.
I. e. after a substring is cut, several first and last letters are left, it is allowed only to glue the last letters to the right of the first letters.
At first, I was puzzled by the two statements ....
The question is very important. TAT
========================================================== ========================================================== ========================================================== ====================
~~ Gorgeous split line ~~
Because it can only be split into consecutive segments, there are only three possible cases.
1. CODEFORCES ------
2. ----- CODEFORCES
3. The first half of CODEFORCES ----- the second half of CODEFORCES
Method 1: 15 ms
# Include <iostream> # include <cstring> # include <cstdio> # include <string> using namespace std; // char s [100 + 10]; string s, str1, str2; int main () {char des [11] = "CODEFORCES"; while (cin> s) {int len = s. length (); int flag = 0; if (len <10) {printf ("NO \ n"); continue ;} /// the length is not long enough for (int I = 0; I <= 10; I ++) // here 10 is not len {// memcpy (str, s, I); str1 = s. substr (0, I); // memcpy (str + I, s + I + len-10, 10-i); str2 = s. substr (I + len-10, 10-i); // if (! Strcmp (str, des) if (str1 + str2 = des) {flag = 1; break;} // string can also add Haha} if (flag) printf ("YES \ n"); else printf ("NO \ n");} return 0 ;}
Method 2: 30 ms
# Include <iostream> # include <cstring> # include <cstdio> using namespace std; char s [100 + 10]; int main () {char des [11] = "CODEFORCES", str [11]; // printf ("% s \ n", des ); str [10] = '\ 0'; while (~ Scanf ("% s", s) {int len = strlen (s); // int cnt = 0, k = 0; int flag = 0; if (len <10) {printf ("NO \ n"); continue ;}for (int I = 0; I <= 10; I ++) {memcpy (str, s, I); memcpy (str + I, s + I + len-10, 10-i); // powerful memcpy if (! Strcmp (str, des) {flag = 1; break ;}} if (flag) printf ("YES \ n"); else printf ("NO \ n ");} return 0 ;}
So the question is, why is the first string used faster? Is substr () faster than memcpy? Or is strcmp () Slow?