版本比较
题解:P2262 [HNOI2004] FTP服务器
正文
增加 37 行删除 37 行
70 行未改动7172737475757677787980808182838480 行未改动16516616716816917016917017117217317417517517617717817946 行未改动226227228229230230231232233234181 行未改动全部展开41641741841942042042142242342442542542642742842945 行未改动4754764774784794794804814824837 行未改动4914924934944954954964974984995005015025025035045055068 行未改动5155165175185195195205215225235245255265275285295295305315325333 行未改动53753853954054154154254354454515 行未改动56156256356456556556656756856934 行未改动60460560660760860960860961061161161261361461561561661761861962062062162262362416 行未改动64164264364464564564664764864965065165165265365465565665765865865966066166266366366466566666722 行未改动69069169269369469469569669769869970070070170270370470570570670770870870971071071171271371471571671771871972072072172272372416 行未改动7417427437447457457467477487497507517517527537537547557567573 行未改动7617627637647657657667677687697707707717727737749 行未改动78478578678778878978878979079170 行未改动 }
void check() { bool flag = false; for (auto i = files.begin();i!=files.end();i++){ for (auto i = files.begin();i!=files.end();i++){ if ((*i)->state!=1){ flag = true; break; } } } if (!flag) this->state = 1; }
80 行未改动 // 获取文件(夹) while (true) { string str; cin >> str; if (str == "-") { waitClose--; if (str == "-") { waitClose--; folders.pop(); } else { int size; cin >> size; if (size == 0) { if (size == 0) { waitClose++; Folder* folder = new Folder(str, folders.top()); folders.top()->addFolder(folder); folders.push(folder);46 行未改动 if (!i->isdownload) { if (i->isfile) { i->file->state = 1; i->file->father->check(); } else } else i->folder->state = 1; } if (i->user->state != 3) nowdd--; i->user->state = 3;181 行未改动全部展开 }
void check() { bool flag = false; for (auto i = files.begin();i!=files.end();i++){ for (auto i = files.begin();i!=files.end();i++){ if ((*i)->state!=1){ flag = true; break; } } } if (!flag) this->state = 1; }
45 行未改动 this->istask = false; }
RequestFile search(string target) { for (auto i = position->files.begin();i!=position->files.end();i++) for (auto i = position->files.begin();i!=position->files.end();i++) if ((*i)->name==target) return RequestFile(*i); for (auto i = position->folders.begin();i!=position->folders.end();i++) if ((*i)->name==target)7 行未改动
vector<User*> users;
bool isUser(string name) { for (auto i = users.begin();i!=users.end();i++) for (auto i = users.begin();i!=users.end();i++) if ((*i)->name==name) return true; return false;}
User* getUser(string name) { for (auto i = users.begin();i!=users.end();i++) for (auto i = users.begin();i!=users.end();i++) if ((*i)->name==name) return *i; return NULL_USER;}8 行未改动 Folder* folder; File* file; Task(User* user,int time,int size) { this->user = user; this->time = time; this->time = time; this->remove = false; this->isdownload = true; this->size = size; user->istask = true; user->task = this; }
Task(User* user,int time,int size,Folder* folder) { this->user = user; this->time = time; this->time = time; this->remove = false; this->isdownload = false; this->isfile = false; this->folder = folder;3 行未改动 }
Task(User* user,int time,int size,File* file) { this->user = user; this->time = time; this->time = time; this->remove = false; this->isdownload = false; this->isfile = true; this->file = file;15 行未改动 if (user->istask) user->task->remove = true; if (user->state != 3) nowdd--; for (auto i = users.begin();i!=users.end();i++){ for (auto i = users.begin();i!=users.end();i++){ if ((*i)->name == user->name){ users.erase(i); break; }34 行未改动 //获取文件(夹) while (true) { string str; cin>>str; if (str == "-"){ waitClose--; if (str == "-"){ waitClose--; folders.pop(); } } else { int size; cin>>size; if (size==0){ if (size==0){ waitClose++; Folder* folder = new Folder(str,folders.top()); folders.top()->addFolder(folder); folders.push(folder); } } else { File* file = new File(str,size,folders.top()); folders.top()->addFile(file); }16 行未改动 string ti; cin>>ti; if (ti=="down") break; else else second = stoi(ti,&s); //处理上传和下载 for (auto it = tasks.begin();it!=tasks.end();) { auto i = *it; if (i->remove){ tasks.erase(it++); tasks.erase(it++); continue; }
i->size = i->size - (second-i->time)*userFlux; i->time = second; if (i->size<=0){ if (!i->isdownload) if (!i->isdownload) if (i->isfile) { i->file->state = 1; i->file->father->check(); } else else i->folder->state = 1; if (i->user->state != 3) nowdd--; i->user->state = 3;22 行未改动 else { bool flag = false; User* user = getUser(name); if (user->name=="NULL") flag = true; flag = true; if (command=="download"){ string filename; cin>>filename; if (flag||!checkDownload(user)){ cout<<"unsuccess"<<endl; continue; continue; } RequestFile req = user->search(filename); if (!req.callback||!check(req)) { cout<<"unsuccess"<<endl; continue; continue; } int size; if (req.isFile) if (req.isFile) size = req.file->size; else else size = req.folder->size; user->state = 2; nowdd++; tasks.insert(new Task(user,second,size)); cout<<"success"<<endl; } else if (command=="cd..") { if (flag||user->position->isroot) { cout<<"unsuccess"<<endl; continue; continue; } user->position = user->position->father; cout<<"success"<<endl; }16 行未改动 } RequestFile req = user->search(filename); if (!req.callback||!checkFolder(req)) { cout<<"unsuccess"<<endl; continue; continue; } user->position = req.folder; cout<<"success"<<endl; } else if (command=="quit") { if (flag) { if (flag) { cout<<"unsuccess"<<endl; continue; continue; } removeUser(user); nowCount--; cout<<"success"<<endl;3 行未改动 int size; cin>>filename>>size; if (flag||!checkUpload(user)){ cout<<"unsuccess"<<endl; continue; continue; } RequestFile req = user->search(filename); if (req.callback) { cout<<"unsuccess"<<endl; continue; continue; } user->state = 1; nowdd++; if (size == 0) {9 行未改动 tasks.insert(new Task(user,second,size,file)); } cout<<"success"<<endl; } } } } }}```