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_Day5/main.cpp

55 lines
1.6 KiB

2 years ago
#define OLC_PGE_APPLICATION
#include "pixelGameEngine.h"
#include "olcutils.h"
using namespace olc;
int main()
2 years ago
{
std::ifstream file("input");
std::array<std::string,9>stacks={
{
"ZJNWPS",
"GST",
"VQRLH",
"VSTD",
"QZTDBMJ",
"MWTJDCZL",
"LPMWGTJ",
"NGMTBFQH",
"RDGCPBQW"
},
};
std::string line;
for (int i=0;i<10;i++){
std::getline(file,line);
}
while (file.good()){
std::getline(file,line);
int marker=line.find_first_of(' ');
int prevmarker=0;
int move=std::atoi(line.substr(marker+1,line.find_first_of(' ',marker+1)-marker).c_str());
std::cout<<move<<std::endl;
prevmarker=marker;marker=line.find_first_of(' ',marker+1);
prevmarker=marker;marker=line.find_first_of(' ',marker+1);
int from=std::atoi(line.substr(marker+1,line.find_first_of(' ',marker+1)-marker).c_str());
std::cout<<from<<std::endl;
prevmarker=marker;marker=line.find_first_of(' ',marker+1);
prevmarker=marker;marker=line.find_first_of(' ',marker+1);
int to=std::atoi(line.substr(marker+1,std::string::npos).c_str());
std::cout<<to<<std::endl;
to--;
from--;
stacks[to]+=stacks[from].substr(stacks[from].length()-move,move);
stacks[from]=stacks[from].substr(0,stacks[from].length()-move);
2 years ago
}
for (int i=0;i<stacks.size();i++){
std::cout<<"Stack "<<i+1<<" Top:"<<stacks[i][stacks[i].size()-1]<<std::endl;
}
2 years ago
return 0;
}