You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AoC2022_Day16/main.cpp

57 lines
1.8 KiB

#define OLC_PGE_APPLICATION
#include "pixelGameEngine.h"
#include "olcutils.h"
using namespace olc;
struct Room{
std::vector<std::string>connections;
int flowValue=0;
std::string name="";
friend std::ostream&operator<<(std::ostream&out,Room&rhs){
out<<"Valve "<<rhs.name<<": Flow Rate - "<<rhs.flowValue<<std::endl;
out<<" Connects to: ";
for (int i=0;i<rhs.connections.size();i++){
std::string conn=rhs.connections[i];
if (i!=0){
out<<",";
}
out<<conn;
}
return out;
}
};
int main()
{
std::map<std::string,Room>rooms;
std::ifstream file("input");
while (file.good()){
std::string line;
std::getline(file,line);
std::cout<<line<<std::endl;
if (line.length()>0){
int flowRate=std::atoi(line.substr(line.find('=')+1,line.find(';')-line.find('=')-1).c_str());
std::cout<<"Flow Rate: "<<flowRate<<std::endl;
std::string valveName=line.substr(line.find(' ')+1,2);
std::cout<<"Valve "<<valveName<<std::endl;
int marker=line.find(',');
Room newRoom;
newRoom.name=valveName;
newRoom.flowValue=flowRate;
while (marker!=std::string::npos){
std::string roomName=line.substr(marker-2,2);
std::cout<<"Connection w/"<<roomName<<" found"<<std::endl;
marker=line.find(',',marker+1);
newRoom.connections.push_back(roomName);
}
std::string roomName=line.substr(line.size()-2,2);
std::cout<<"Connection w/"<<roomName<<" found"<<std::endl;
newRoom.connections.push_back(roomName);
rooms[valveName]=newRoom;
std::cout<<rooms[valveName]<<std::endl;
}
}
return 0;
}