#include <iostream> #include <fstream> #include <vector> #include <list> using namespace std; int main(int argc, char *argv[]) { int flog = 1; //用flog表示可以直接输出的车皮号 开始的时候是1 当每次直接输出了之后 要加1 int n = 0; //n表示总共的车皮数量 list<int> objbegin; //用来存放初始的a1,a2,---,an ifstream fin("input.txt", ios::in); //打开读取的文件; fin >> n; for(int i = 0; i < n; ++i){ //读取和n个车皮的初始编号a1,a2---,an int temp = 0; fin >> temp; objbegin.push_back(temp); }/*------end of for------*/ fin.close(); list<vector<int> > H; while(!objbegin.empty()){ list<int>::iterator pos = objbegin.begin(); int temp = *pos; objbegin.pop_front(); if(temp == flog){ ++flog; continue; //自己做循环 不需要 } if(H.empty()){ vector<int> tempdeque; tempdeque.push_back(temp); H.push_back(tempdeque); } else { list<vector<int> >::iterator pos1 = H.begin(); while(pos1 != H.end()){ if(pos1->back() > temp){ pos1->push_back(temp); break; } ++pos1; } /*------end of while------*/ if(pos1 == H.end()){ vector<int> tempdeque1; tempdeque1.push_back(temp); H.push_back(tempdeque1); } } } /*------end of while------*/ ofstream fout("output.txt", ios::out); fout << "H.size() : " << H.size() << endl; fout.close(); return 0; } /*------end of main------*/ 第一组实验input.txt42 3 4 1 output.txt3第二组实验input.txt121 12 8 9 2 3 4 6 5 7 10 11output.txt