Original title Address
List+map can be easily done, if not with the use of STL implementation is still very troublesome
Code:
1#include <iostream>2#include <string>3#include <list>4#include <map>5 6 using namespacestd;7 8 intN, M;9map<string, list<string>::iterator>record;Tenlist<string>Cache; One intSize =0; A - intMain () { - stringURL; the -CIN >> N >>M; - while(n--) { -CIN >>URL; +Auto P =record.find (URL); - if(P! =Record.end ()) { +Cache.erase (p->second); ACache.push_front (p->First ); atcout <<"Cache"<<Endl; - } - Else if(Size >=M) { - record.erase (Cache.back ()); - Cache.pop_back (); - cache.push_front (URL); inRecord.insert (pair<string, list<string>::iterator>(URL, Cache.begin ())); -cout <<"Internet"<<Endl; to } + Else { - cache.push_front (URL); thesize++; *Record.insert (pair<string, list<string>::iterator>(URL, Cache.begin ())); $cout <<"Internet"<<Endl;Panax Notoginseng } - } the return 0; +}
hihocoder#1086 Browser Caching