120 Stacks of Flapjacks

就是翻转饼干的题目,代码写得不是很好,算了
#include <iostream> #include <string> #include <algorithm> #include <sstream> #include <vector> //#include <iterator> //#include "boost/foreach.hpp" using namespace std; int main() { //循环处理输入的每组字符串。每次循环一轮要输出最后的0和换行 for (string strLine; getline(cin, strLine); cout << '0' << endl) { //按要求回应输入的字符串行 cout << strLine << endl; //构造字符串流,以遍转换为数字 istringstream iss(strLine); vector<int> v; int n; for( ; iss>>n ; v.push_back(n)) ; { int len,tempLen; len = tempLen = v.size(); tempLen; while(tempLen > 1) { int back = tempLen-1; int maxNum = v.at(back); int maxPos = back; --back; while(back >= 0) { if(v[back]>maxNum) { maxPos = back; maxNum = v[back]; } --back; } if(maxPos != tempLen-1) { int out_pos = len-maxPos; if(out_pos != len) { cout<<out_pos<<' '; reverse(v.begin(),v.begin()+maxPos+1); } out_pos = len-tempLen+1; cout<<out_pos<<' '; reverse(v.begin(),v.begin()+tempLen); } tempLen--; } } //cout<<"endl\n"; } return 0; }
原文地址:https://www.cnblogs.com/UnGeek/p/2580999.html