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

46 lines
1.5 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");
int sum=0;
while (file.good()) {
std::string line;
std::getline(file,line);
int marker=0;
int prevmarker=0;
prevmarker=marker;marker=line.find_first_of('-');
int digit1=std::atoi(line.substr(0,marker).c_str());
prevmarker=marker;marker=line.find_first_of(',',marker);
int digit2=std::atoi(line.substr(prevmarker+1,marker-prevmarker).c_str());
prevmarker=marker;marker=line.find_first_of('-',marker);
int digit3=std::atoi(line.substr(prevmarker+1,marker-prevmarker).c_str());
prevmarker=marker;marker=line.find_first_of('\n',marker);
int digit4=std::atoi(line.substr(prevmarker+1,marker-prevmarker).c_str());
//1-3 3-5 // 3-5 1-3
//1-4 4-7
//1-3 4-9
//4-6 5-9
//6-9 1-7 // 1-7 6-9
2 years ago
if (digit1<=digit4&&digit2>=digit3||digit2>=digit3&&digit1<=digit4) {
sum++;
std::cout<<line<<std::endl;
std::cout<<digit1<<","<<digit2<<","<<digit3<<","<<digit4<<std::endl;
std::cout<<"In Range"<<std::endl;
2 years ago
} else {
std::cout<<line<<std::endl;
std::cout<<digit1<<","<<digit2<<","<<digit3<<","<<digit4<<std::endl;
std::cout<<"NOT In Range"<<std::endl;
2 years ago
}
}
std::cout<<"Sum: "<<sum<<std::endl;
2 years ago
return 0;
}