generated from sigonasr2/CPlusPlusProjectTemplate
Finally, test input matches up
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
fe8044562a
commit
dd63de88e4
Binary file not shown.
28
main.cpp
28
main.cpp
@ -3,7 +3,7 @@
|
|||||||
#include "olcutils.h"
|
#include "olcutils.h"
|
||||||
|
|
||||||
using namespace olc;
|
using namespace olc;
|
||||||
std::ifstream file("testinput");
|
std::ifstream file("input");
|
||||||
std::map<std::string,int> filedata;
|
std::map<std::string,int> filedata;
|
||||||
std::string pwd;
|
std::string pwd;
|
||||||
std::string tempstr;
|
std::string tempstr;
|
||||||
@ -28,6 +28,24 @@ int DisplayContents(File&f,std::string path,int filter,int*filtersum){
|
|||||||
return sum+f.size;
|
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()
|
int main()
|
||||||
{
|
{
|
||||||
File rootFile{{},0};
|
File rootFile{{},0};
|
||||||
@ -146,8 +164,14 @@ int main()
|
|||||||
std::cout<<line<<std::endl;
|
std::cout<<line<<std::endl;
|
||||||
}
|
}
|
||||||
int sum=0;
|
int sum=0;
|
||||||
DisplayContents(rootFile,"/",100000,&sum);
|
int totalSpace=DisplayContents(rootFile,"/",100000,&sum);
|
||||||
|
int diskSpace=70000000;
|
||||||
std::cout<<"Sum: "<<sum<<std::endl;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user