zhangsongcui

Untitled

Nov 8th, 2011
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <deque>
  3. #include <algorithm>
  4. #include <queue>
  5.  
  6. int main()
  7. {
  8.     using namespace std;
  9.     deque<int> page{ 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 };
  10.     deque<int> frame;
  11.     unsigned count = 0;
  12.     while (!page.empty())
  13.     {
  14.         int nowUsed = page.front();
  15.         page.pop_front();
  16.         if (find(frame.begin(), frame.end(), nowUsed) != frame.end())
  17.             continue;
  18.         if (frame.size() == 3)
  19.         {
  20.             ++count;
  21.             cout << frame.front() << ' ';
  22.             frame.pop_front();
  23.         }
  24.         frame.push_back(nowUsed);
  25.         cout << "缺页次数" << count << endl;
  26.     }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment