#include #include #include #include #include int main(int argc, char* argv[]){ std::cout<<"paste input followed by a ;\n"; std::vector inp; std::string line; std::string wd = "/"; std::map tree; while(getline(std::cin, line)){ if(line==";") break; if(line[0]=='$'){ if(line[2]=='c'){ //change dir line.erase(0,5); if(line==".."){ wd.erase(wd.size()-1,1); for(int i = wd.size();i!=0;i--){ if(wd[i]=='/') break; wd.erase(i,1); } } else { wd+=line+"/"; if(line=="/") wd="/"; } } else { //list dir, just ignore lmao tree.insert(std::pair(wd,0)); } } else { if(line[0]!='d'){ //not a dir std::string temp = ""; for(char c : line){ if(c==' ') break; temp+=c; } tree[wd]+=stoi(temp); std::map::iterator itr1; for (itr1 = tree.begin(); itr1 != tree.end(); ++itr1) { if(wd.find(itr1->first) != std::string::npos&&wd!="/"&&itr1->first!=wd){ tree[itr1->first]+=stoi(temp); } } } } //std::cout<::iterator itr; for (itr = tree.begin(); itr != tree.end(); ++itr) { //std::cout << '\t' << itr->first << '\t' << itr->second<< '\n'; if(itr->second<=100000){ total+=itr->second; } } std::vector possible = {}; for (itr = tree.begin(); itr != tree.end(); ++itr) { if(unused+itr->second>=NEEDED){ possible.push_back(itr->second); } } std::sort(possible.begin(),possible.end()); std::cout<<"part 1 :"<