fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n,aux,mx,ind,j,i,V[40];
  4. int main(){
  5.  
  6. string s;
  7. while(getline(cin,s)){
  8. n=0;
  9. istringstream is(s);
  10. cout<<s<<endl;
  11. while(is>>aux) V[n++]=aux;
  12. for( i=n-1;i>=0;i--){
  13. mx=-1;
  14. for( j=0;j<=i;j++)
  15. if(mx<=V[j]){
  16. mx=V[j];
  17. ind=j;
  18. }
  19. if(ind != i){
  20. if(ind != 0){
  21. printf("%d ", n-ind);
  22. for( j=0;j<=ind/2;j++) swap(V[j],V[ind-j]);
  23. }
  24. printf("%d ", n-i);
  25. for(int j=0;j<=i/2;j++) swap(V[j],V[i-j]);
  26. }
  27. }
  28. printf("0\n");
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5308KB
stdin
3 4 5 2 1
1 5 2 4 3
stdout
3 4 5 2 1
3 1 0
1 5 2 4 3
4 1 4 2 0