#include<iostream>
#include<string>
#include<cassert>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<set>
#include<sstream>
#include<queue>
#include<unordered_map>
using namespace std;
bool is_sorted(int x[], int n)
{
bool ok = true;
for (int i = 0; i < n - 1; ++i)
{
if (x[i] > x[i + 1])
ok = false;
}
return ok;
}
int main() {
//freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
string line;
while (getline(cin, line))
{
int x[50];
stringstream ss(line);
int n = 0;
while (ss >> x[n])
{
++n;
}
int y[50];
memcpy(y, x, sizeof(y));
sort(y, y + n);
cout << x[0];
for (int i = 1; i < n; ++i)
{
cout << " " << x[i];
}
cout << endl;
for (int i = 0; i < n - 1; ++i)
{
if (is_sorted(x, n))
break;
while (y[n - i - 1] == x[n - i - 1])
{
++i;
}
int max = -1;
int imax = -1;
for (int j = 0; j < n - i; ++j)
{
if (x[j] > max)
{
max = x[j];
imax = j;
}
}
if (imax != 0)
{
reverse(x, x + imax + 1);
cout << n - imax << " ";
}
reverse(x, x + n - i);
cout << i + 1 << " ";
}
cout << "0" << endl;
}
}
紫书 煎饼UVa120
最新推荐文章于 2024-07-25 21:13:04 发布