title: lexicographically smallest string after rotation
body: <p>I am trying to solve <a href="http://www.spoj.com/problems/MINMOVE/" rel="nofollow">this problem in spoj</a></p>
  
  <p>I need to find the number of rotations of a given string that will make it lexicographically smallest among all the rotations. </p>
  
  <p>For example:</p>
  
  <p>Original: <code>ama</code></p>
  
  <p>First rotation: <code>maa</code></p>
  
  <p>Second rotation: <code>aam</code> This is the lexicographically smallest rotation so the answer is 2.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>string s,tmp;
      char ss[100002];
      scanf("%s",ss);
      s=ss;
      tmp=s;
      int i,len=s.size(),ans=0,t=0;
      for(i=0;i&lt;len;i++)
      {
          string x=s.substr(i,len-i)+s.substr(0,i);
          if(x&lt;tmp)
          {
              tmp=x;
              t=ans;
          }
          ans++;
      }
  
      cout&lt;&lt;t&lt;&lt;endl;
  </code></pre>
  
  <p>I am getting "Time Limit Exceeded" for this solution. I don't understand what optimizations can be made. How can I increase the speed of my solution?</p>