added line precessing
This commit is contained in:
parent
0d4f948ff5
commit
b4232c905d
3 changed files with 48 additions and 12 deletions
|
|
@ -8,9 +8,12 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
int main(){
|
||||
enum Direction {
|
||||
UP,
|
||||
DOWN
|
||||
};
|
||||
|
||||
list<int> currntlevels{};
|
||||
int main(){
|
||||
string line;
|
||||
int safeReports = 0;
|
||||
|
||||
|
|
@ -18,16 +21,44 @@ int main(){
|
|||
|
||||
while (getline(puzzle, line)) {
|
||||
istringstream lineStream(line);
|
||||
string number;
|
||||
cout << "{";
|
||||
while (getline(lineStream, number, ' ')) {
|
||||
cout << number<<"|";
|
||||
string numberString;
|
||||
list<int> currentLevels;
|
||||
while (getline(lineStream, numberString, ' ')) {
|
||||
int number = stoi(numberString);
|
||||
currentLevels.push_back(number);
|
||||
}
|
||||
|
||||
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 (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 << "}";
|
||||
}
|
||||
/*
|
||||
for (line; !puzzle.eof();puzzle.getline(line,'\n')) {
|
||||
cout << line << "\n";
|
||||
}
|
||||
*/
|
||||
cout << safeReports;
|
||||
puzzle.close();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue