Let's say that we have the string "ABCAD", now we need to iterate all possible location of this string both clockwise and counterclockwise.
My ugly implementation is as follows:
string s = "ABCAD"; string t =""; for(int i = 0; i < sz(s); i++){ t = s[i]; for(int j = i+1; ; j++){ if((j) == sz(s)){ j = 0; } if(j == i){ break; } t+= s[j]; } cout<<t<<" "; } reverse(all(s)); for(int i = 0; i < sz(s); i++){ t = s[i]; for(int j = i+1; ; j++){ if((j) == sz(s)){ j = 0; } if(j == i){ break; } t+= s[j]; } cout<<t<<" "; }
Conclusion:
AHSAU HSAUA SAUAH AUAHS UAHSA UASHA ASHAU SHAUA HAUAS AUASH
I know that a too naive, AFAIK circular list would be a better choice, can someone more effectively implement the same with STL?
source share