fork download
  1. #include<stdio.h>
  2. #include<string.h>
  3. #define MAX 20011
  4.  
  5. int main(){
  6. int c, len, i, j, sol;
  7. char tmp[MAX];
  8. scanf("%d", &c);
  9. while(c--){
  10. sol = 0;
  11. scanf("%s", tmp);
  12. len = strlen(tmp);
  13. strncpy(tmp+len, tmp, len);
  14. for( i = 1; i < len; ++i){
  15. if( strncmp(tmp+i, tmp+sol, len) < 0)
  16. sol = i;
  17. }
  18. printf("%d\n", sol+1);
  19. }
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0.01s 1680KB
stdin
2
helloworld
abbaa
stdout
10
4