Practice using String functions.
1, the word string reversal is also its string, 2, the longest, 3, the first appearance
String
#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>using namespacestd;intMain () {intT, N; strings; CIN>>T; while(t--) {cin>>s; intn =s.size (); for(intI=n; i>=1; i--) {//Enumeration Length for(intj=0; j+i-1<n; J + +) {//Enumeration Start stringTS =S.substr (J, I); Reverse (Ts.begin (), Ts.end ()); if(S.find (ts)! =string:: NPOs) {cout<<s.substr (J, i) <<Endl; GotoHere ; }}} here:; } return 0;}
Char[], the time is half the upper
#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<cmath>using namespacestd;#defineN 52CharS[n];CharTs[n];intMain () {intT, N; scanf ("%d", &t); while(t--) {scanf ("%s", s); intn =strlen (s); for(intI=n; i>=1; i--) {//Enumeration Length for(intj=0; j+i-1<n; J + +) {//Enumeration Startstrncpy (TS, s+J, I); Ts[i]=' /'; Reverse (TS, TS+i); if(Strstr (s, ts)! =NULL) {strncpy (ts, S+J, I); Ts[i]=' /'; cout<<ts<<Endl; GotoHere ; }}} here:; } return 0;}
[Henan Province ACM Province-fourth session] Substring (Nyoj 308)