Finally, test input matches up

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent fe8044562a
commit dd63de88e4
  1. BIN
      C++ProjectTemplate
  2. 28
      main.cpp

Binary file not shown.

@ -3,7 +3,7 @@
#include "olcutils.h"
using namespace olc;
std::ifstream file("testinput");
std::ifstream file("input");
std::map<std::string,int> filedata;
std::string pwd;
std::string tempstr;
@ -28,6 +28,24 @@ int DisplayContents(File&f,std::string path,int filter,int*filtersum){
return sum+f.size;
}
int GetSmallestAboveThreshold(File&f,std::string path,int remaining,int*smallest){
//std::cout<<" Contents of "<<path<<"(Size "<<f.size<<"): "<<std::endl;
int sum=0;
for (std::map<std::string,File>::iterator it=f.files.begin();it!=f.files.end();it++){
int amt=GetSmallestAboveThreshold(it->second,(path=="/")?path+it->first:path+"/"+it->first,remaining,smallest);
if (amt>=remaining){
std::cout<<"Remaining: "<<remaining<<" My Sum:"<<amt<<std::endl;
if (amt<*smallest&&path!="/"){
*smallest=amt;
}
}
sum+=amt;
}
//std::cout<<" Size of "<<path<<": "<<sum<<std::endl;
return sum+f.size;
}
int main()
{
File rootFile{{},0};
@ -146,8 +164,14 @@ int main()
std::cout<<line<<std::endl;
}
int sum=0;
DisplayContents(rootFile,"/",100000,&sum);
int totalSpace=DisplayContents(rootFile,"/",100000,&sum);
int diskSpace=70000000;
std::cout<<"Sum: "<<sum<<std::endl;
std::cout<<"Disk space used: "<<totalSpace<<std::endl;
int remaining=30000000-(diskSpace-totalSpace);
int smallest=diskSpace;
int deleteSize=GetSmallestAboveThreshold(rootFile,"/",remaining,&smallest);
std::cout<<"Smallest to delete: "<<deleteSize<<std::endl;
return 0;
}

Loading…
Cancel
Save