aoc/2022/day-6.cpp

46 lines
1.1 KiB
C++

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
int main(int argc, char* argv[]){
std::cout<<"paste input followed by a ;\n";
std::vector<std::string> inp;
std::string line;
while(getline(std::cin, line)){
if(line==";")
break;
inp.push_back(line);
}
int p1 = 0;
for(std::string ss : inp){
std::string temp = "";
for(int i = 0; i!=ss.size();i++){
if(temp.size()==4&&p1==0){
std::cout<<"part 1 :"<<i<<std::endl;
p1=1;
//break;
}
if(temp.size()>=14){
std::cout<<"part 2 :"<<i;
break;
}
if(temp.find(ss[i]) != std::string::npos){
for(int z = 0; z<=temp.size();z++){
if(temp[z]==ss[i]){
for(int zz = z; zz>=0;zz--){
temp.erase(0,1);
}
break;
}
}
temp+=ss[i];
} else {
temp+=ss[i];
}
}
}
//std::cout<<"failed";
return 0;
}