UVA(120)

版权声明:欢迎转载!拒绝抄袭. https://blog.csdn.net/qq_36257146/article/details/89819046
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
vector<int>a;

int main()
{
    string s;
    int num;
    while(getline(cin,s))
    {
        cout<<s<<endl;
        a.clear();
        stringstream ss(s);
        while(ss>>num)
        {
            a.push_back(num);
        }
        int len = a.size();
        for(int i = 0; i<len; i++)
        {
            int k = max_element(a.begin(),a.end()-i)-a.begin();
            if(k!=len-i-1)
            {
                if(k!=0)
                {
                    cout<<len-k<<" ";
                    reverse(a.begin(),a.begin()+k+1);
                }
                cout<<i+1<<" ";
                reverse(a.begin(),a.end()-i);
            }

        }
        cout<<0<<endl;

    }
    return 0;
}
/**
1 2 3 4 5
5 4 3 2 1
5 1 2 3 4
**/

猜你喜欢

转载自blog.csdn.net/qq_36257146/article/details/89819046
120