KMP

complex logic
rotate string

reverse the string twice, and it 's done
grading, clock, and so on

exercise on jobdu online judge