1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
#include <iostream>
#include <vector>
#include <sstream>
#include <algorithm>
#include <sstream>
using namespace std;
vector< vector<int> > allTests;
vector<int> currSituation;
string line, instruc;
string* pInstruct=&instruc;
int i;
int numTests, numPancakes;
void printInstruc(vector <int> unsorted,vector <int> sorted, int curPan, int vecSize, string* instructions) {
if (vecSize==1) {
cout << unsorted[0] << endl;
cout << 0 << endl;
}
bool alwaysBigger;
bool spaceBefore=true;
int curDiam;
if (curPan==vecSize-1) {
return;
}
if (curPan==1) {
sort(sorted.begin(), sorted.end());
spaceBefore=false;
for (int loop=0; loop<vecSize; loop++) {
if (spaceBefore) cout << " ";
cout << unsorted[loop];
spaceBefore=true;
}
spaceBefore=false;
cout << endl;
}
curDiam=*(sorted.end()-curPan);
for (int loop=1; loop<=vecSize; loop++) {
if (*(unsorted.end()-loop)==curDiam) {
if (loop==curPan) break;
if (loop!=vecSize) {
stringstream ss;
ss<<loop;
if (spaceBefore) {
*instructions+=" ";
}
*instructions+=ss.str();
spaceBefore=true;
reverse(unsorted.begin(), unsorted.end()-loop+1);
}
if (spaceBefore) {
*instructions+=" ";
}
stringstream ss;
ss<<curPan;
*instructions+=ss.str();
spaceBefore=true;
reverse(unsorted.begin(),unsorted.end()-curPan+1);
break;
}
}
printInstruc(unsorted, sorted, curPan+1, vecSize, instructions);
if (curPan==1) {
cout << *instructions;
if (spaceBefore)cout << " ";
cout << "0" << endl;
}
return;
}
int numCases;
int main()
{
while (getline(cin, line, '\n')) {
currSituation.clear();
if (line=="") continue;
stringstream ss(line);
while (ss>>i){
currSituation.push_back(i);
}
allTests.push_back(currSituation);
*pInstruct="";
printInstruc(currSituation,currSituation,1,currSituation.size(), pInstruct);
}
return 0;
}
|