#include <iostream>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
const int MAXN = 30;
vector<int> v;
void reverse(int a[], int top, int bottom) {
for (int i = top; i <= (top + bottom)/2; i++) {
int temp = a[i];
a[i] = a[top + bottom - i];
a[top + bottom - i] = temp;
}
}
void flip_sort(int a[], int dpt) {
v.clear();
for (int i = 0; i < dpt; i++) {
int max = a[0];
int index = 0;
for (int j = 0; j < dpt - i; j++) {
if (a[j] > max) {
max = a[j];
index = j;
}
}
if (index == dpt - i - 1) continue;
else {
if (index != 0) {
reverse(a, 0, index);
v.push_back(dpt - index);
}
reverse(a, 0, dpt - i - 1);
v.push_back(i + 1);
}
}
v.push_back(0);
}
int main() {
int a[MAXN], b[MAXN];
string str;
while (getline(cin, str)) {
int cnt = 0;
stringstream ss;
ss << str;
memset(a, 0, sizeof(a));
while (ss >> a[cnt])
cnt++;
for (int i = 0; i < cnt; i++)
b[i] = a[i];
flip_sort(a, cnt);
cout << b[0];
for (int i = 1; i < cnt; i++)
cout << ' ' << b[i];
cout << endl;
cout << *v.begin();
for (auto i = ++v.begin(); i != v.end(); i++)
cout << ' ' << *i;
cout << endl;
}
return 0;
}
1.下标的问题还是要注意
2.连续的数字输入目前除了string stream没发现什么好办法
3.debug要做在提交前
4.读英文题目的能力还要加强
5.辣鸡udebug样例(滑稽
PS:写题这个东西还是要坚持,课业再重也要一点点进步。熟能生巧,投入了会有收获的。