uva120


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> ans;
char str[256];
int a[31];
int sorted[31];
int cnt;

void flap(int p){
    ans.push_back(p+1);
    for(int i=0;i<p/2;i++){
        swap(a[i],a[p-i]);
    }
    printf("debug:  ");
    for(int i=0;i<cnt;i++){
        printf("%d ", a[i]);
    }
    printf("\n");

}


int main ()
{

//  cin.getline(str, 256);
//  char * pch;
//  pch = strstr (str,"simple");
//  strncpy (pch,"sample",6);
//  puts (str);
  while(cin.getline(str, 256)){
      char *loc;
      cnt = 0;
      ans.clear();
      a[cnt++] = atoi(str);
      loc = strstr(str, " ");
      while(loc != NULL){
        a[cnt++] = atoi(loc);
        loc = strstr(loc + 1, " ");
      }
      for(int i=0;i<cnt;i++){
        sorted[i] = a[i];
      }
      sort(sorted,sorted+cnt);
      printf("debug sort:  ");
      for(int i=0;i<cnt;i++){
         printf("%d ", sorted[i]);
      }
      printf("\n");
      for(int j=cnt-1;j>=0;j--){
        if(a[j]!=sorted[j]){
            printf("!equ %d\n", a[j]);
            int pos;
            for(pos = 0; pos <= j; pos++){
                if(a[pos]==sorted[j]){
                    break;
                }
            }
            if(pos!=0){
                flap(pos);
            }
            flap(j);
        }
      }
      for(int i=0;i<ans.size();i++){
        printf("%d ", ans[i]);
      }
      printf("\n");


  }

  return 0;
}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 因偶然了解到一条生活馆,其中甚多欢喜之物,思虑再三后的购买,只为不负那份追寻,遂有如下分享!当然,任何人无法拒绝美...
    another琼阅读 909评论 0 0
  • 陈宝宝在我出门上学前还是很可爱的一只小仔仔,然而等到我回家时,真的吓到我了。这完全是只猪啊!踩了我一脚之后真的生无...
    Yanx_阅读 143评论 0 0
  • 本文参加#印象青农,萌有感受#活动,本文承诺,文章内容为原创,且未在其他平台发表过。 一座城,一场梦。...
    青衫忆i阅读 545评论 1 14
  • 占位符
    呵呵哒1991阅读 354评论 4 0