I am depressed and want the longest reply string;
It reads a text string containing punctuation marks, and then ignores the punctuation marks when retrieving the string. The output also outputs the punctuation marks ............
It hurts for a long time. Fortunately, we can see no examples. However, I don't think I have hoped for any more ............
Orz, the "\ n" in the text is also valid ......
Use the previous one to find the longest input stringAlgorithmIt's easy. It's mainly about dealing with the punctuation ......
/* ID: nanke691lang: C ++ task: calfflac */# include <iostream> # include <fstream> # include <string. h> # define maxn 20010 using namespace STD; char str1 [maxn], str2 [maxn * 2]; int N, L1, mid, Len; int NXT [maxn * 2]; void manacher () {int MX = 0, ID; Len =-1; memset (NXT, 0, sizeof (NXT); For (INT I = 1; I <L1; I ++) {If (MX> I) NXT [I] = min (NXT [2 * ID-I], Mx-I); else NXT [I] = 1; for (; str2 [I-NXT [I] = str2 [I + NXT [I]; NXT [I] ++ ); if (MX <I + NXT [I]) {MX = I + NXT [I]; Id = I;} If (LEN <NXT [I]-1) {Len = NXT [I]-1; Mid = I ;}} void pre () {str2 [0] = '$'; int I = 0, T = 0, k = 1; while (str1 [I]! = '\ 0') {If (t) {int flag = 0; while (1) {If (str1 [I]> = 'A' & str1 [I] <= 'Z ') | (str1 [I]> = 'A' & str1 [I] <= 'Z') break; If (str1 [I] = '\ 0 ') {flag = 1; break;} I ++;} If (FLAG) break; str2 [k ++] = str1 [I ++];} else str2 [k ++] = '#'; If (str2 [k-1]> = 'A' & str2 [k-1] <= 'Z ') str2 [k-1] + = 32; t ^ = 1;} str2 [K + +] = '#'; str2 [k] = '\ 0'; L1 = K ;} void print (INT s) {int COUNT = 0, flag = 0; For (INT I = s; str1 [I]! = '\ 0'; I ++) {If (str1 [I]> = 'A' & str1 [I] <= 'Z ') | (str1 [I]> = 'A' & str1 [I] <= 'Z') Count ++; printf ("% C ", str1 [I]); If (COUNT = Len) break;} printf ("\ n");} int main () {freopen ("calfflac. in "," r ", stdin); freopen (" calfflac. out "," W ", stdout); char STR [maxn]; while (gets (STR) {strcat (str1," \ n "); strcat (str1, str);} Pre (); // printf ("% s \ n", str2); manacher (); printf ("% d \ n", Len ); int COUNT = 0, S = (mid-len)/2 + 1; for (INT I = 0; str1 [I]! = '\ 0'; I ++) {If (str1 [I]> = 'A' & str1 [I] <= 'Z ') | (str1 [I]> = 'A' & str1 [I] <= 'Z') Count ++; If (COUNT = s) {print (I); break;} return 0 ;}