1 #define _for(i,a,b) for(int i = (a);i < b;i ++) 2 3 bool judge(string s,int i,int j,int len) 4 { 5 _for(k,0,len) 6 if(s[i]!=s[j]) 7 return false; 8 else 9 i ++,j ++; 10 return true; 11 } 12 class Solution 13 { 14 public: 15 int longestDecomposition(string text) 16 { 17 int i = 0; 18 int j = text.size()-1; 19 int lastj = j; 20 int rnt = 0; 21 while(i<j) 22 { 23 if(text[i]==text[j] && judge(text,i,j,lastj-j+1)) 24 { 25 rnt ++; 26 i += lastj-j+1; 27 lastj = j-1; 28 } 29 j --; 30 } 31 rnt *= 2; 32 if(i<=j) 33 rnt ++; 34 return rnt; 35 } 36 };