fork download
  1. # include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. typedef long double ld;
  6. typedef pair<ll, ll> pll;
  7. typedef vector<ll> vll;
  8. typedef set<ll> sll;
  9.  
  10. #define out1(x)cout<<#x<<" is "<<x<<endl
  11. #define out2(x,y)cout<<#x<<" is "<<x<<" "<<#y <<" is "<<y<<endl
  12. #define out3(x,y,z)cout<<#x<<" is "<<x<<" "<<#y<<" is "<<y<<" "<<#z<<" is "<<z<<endl;
  13. #define out4(a,b,c,d)cout<<#a<<" is "<<a<<" "<<#b<<" is "<<b<<" "<<#c<<" is "<<c<<" "<<#d<<" is "<<d<<endl;
  14. #define show(i,a,n) for(i=0;i<n;i++)cout<<a[i]<<" ";cout<<endl;
  15. #define exectime() cout<<"execution time "<<(double)(clock() - tStart)/CLOCKS_PER_SEC<<endl;
  16.  
  17.  
  18. #define mp(a, b) make_pair(a, b)
  19. #define pb(a) push_back(a)
  20. #define F first
  21. #define S second
  22. #define PI 3.14159265359
  23. #define FastIn std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  24. #define swap(VAR1,VAR2) VAR1=VAR1^VAR2;VAR2=VAR1^VAR2;VAR1=VAR1^VAR2
  25.  
  26. const ll MAXN = ll(5e6);
  27. const ll INF = ll(1e17);
  28. const ld EPS = ll(1e-9);
  29. const ll MOD = ll(1e9) + 7;
  30. const ll MILLION = ll(1e6);
  31. const ll BILLION = ll(1e9);
  32. const ll ONE = ll(1);
  33.  
  34. int main(){
  35. FastIn;
  36. clock_t tStart = clock();
  37.  
  38. string str,s,temp;
  39. ll i,j,l;
  40.  
  41. cin>>str;
  42.  
  43. s = str;
  44. j = 0;
  45.  
  46. l = s.size();
  47.  
  48. for(i=0;i<l;i++){
  49. temp = string(str.begin() + i,str.end()) + string(str.begin(),str.begin() + i);
  50.  
  51. if(temp < s){
  52. s = temp;
  53. j = i;
  54. }
  55. }
  56.  
  57. printf("%lld",j);
  58.  
  59. //exectime();
  60. return 0;
  61. }
Success #stdin #stdout 0s 3284KB
stdin
mississippi
stdout
10