added line precessing
This commit is contained in:
parent
0d4f948ff5
commit
b4232c905d
3 changed files with 48 additions and 12 deletions
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"*.tcc": "cpp"
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
2/puzzle2
BIN
2/puzzle2
Binary file not shown.
|
|
@ -8,9 +8,12 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main(){
|
enum Direction {
|
||||||
|
UP,
|
||||||
|
DOWN
|
||||||
|
};
|
||||||
|
|
||||||
list<int> currntlevels{};
|
int main(){
|
||||||
string line;
|
string line;
|
||||||
int safeReports = 0;
|
int safeReports = 0;
|
||||||
|
|
||||||
|
|
@ -18,16 +21,44 @@ int main(){
|
||||||
|
|
||||||
while (getline(puzzle, line)) {
|
while (getline(puzzle, line)) {
|
||||||
istringstream lineStream(line);
|
istringstream lineStream(line);
|
||||||
string number;
|
string numberString;
|
||||||
cout << "{";
|
list<int> currentLevels;
|
||||||
while (getline(lineStream, number, ' ')) {
|
while (getline(lineStream, numberString, ' ')) {
|
||||||
cout << number<<"|";
|
int number = stoi(numberString);
|
||||||
|
currentLevels.push_back(number);
|
||||||
}
|
}
|
||||||
cout << "}";
|
|
||||||
|
int numOfLevelsInLine = currentLevels.size();
|
||||||
|
int numOfLevelsProcessed = 0;
|
||||||
|
|
||||||
|
//need to pull the first one to have something to compare to
|
||||||
|
enum Direction dir;
|
||||||
|
int prevlevel = currentLevels.front();
|
||||||
|
currentLevels.pop_front();
|
||||||
|
numOfLevelsProcessed++;
|
||||||
|
if (prevlevel - currentLevels.front()>0){
|
||||||
|
dir = UP;
|
||||||
|
} else if (prevlevel - currentLevels.front()< 0){
|
||||||
|
dir = DOWN;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
for (line; !puzzle.eof();puzzle.getline(line,'\n')) {
|
|
||||||
cout << line << "\n";
|
for (int level = 0; !currentLevels.empty();level=currentLevels.front()){
|
||||||
|
if (abs(prevlevel-level)>3) {currentLevels.clear();break;}
|
||||||
|
if(prevlevel-level==0){ currentLevels.clear();break;}
|
||||||
|
if(dir==UP&&(prevlevel-currentLevels.front())<0) {currentLevels.clear();break;}
|
||||||
|
if(dir==DOWN&&(prevlevel-currentLevels.front()>0)) {currentLevels.clear();break;}
|
||||||
|
|
||||||
|
prevlevel=currentLevels.front();
|
||||||
|
currentLevels.pop_front();
|
||||||
|
|
||||||
|
if(numOfLevelsProcessed==numOfLevelsInLine){
|
||||||
|
safeReports++;
|
||||||
}
|
}
|
||||||
*/
|
}
|
||||||
|
}
|
||||||
|
cout << safeReports;
|
||||||
|
puzzle.close();
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue