zoukankan      html  css  js  c++  java
  • 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; }
  • 相关阅读:
    筛选法 || POJ 1356 Prime Land
    搜索 || BFS || POJ 3278 Catch That Cow
    (素数筛) 找质数
    (map)后缀字符串
    字符串的进制
    (二进制枚举子集)买玩具
    (基础)01背包问题
    (基础)编辑距离
    (基础)最长公共字串
    最大子矩阵和
  • 原文地址:https://www.cnblogs.com/UnGeek/p/2580999.html
Copyright © 2011-2022 走看看