diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2024-12-02 18:55:01 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2024-12-02 18:55:01 +0800 |
| commit | 15eba4f2ee416b26f36252751e1299ee9f0144ff (patch) | |
| tree | 5a40bd1f9b563fe32feb72a66db7bf237e0fee6d /2024/2A.cpp | |
| parent | 06cb6964aeb5444f29abc3c7966e6799d21f43f4 (diff) | |
add: 2A.cpp
Diffstat (limited to '2024/2A.cpp')
| -rw-r--r-- | 2024/2A.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/2024/2A.cpp b/2024/2A.cpp new file mode 100644 index 0000000..c8a5a19 --- /dev/null +++ b/2024/2A.cpp @@ -0,0 +1,41 @@ +#include <bits/stdc++.h> +#include "readfile.hpp" + + +int main(int argc, char const *argv[]) +{ + int res = 0; + std::vector<std::string> file = readfile("2A.in"); + if (file.empty()) + return 1; + + for (const auto &line : file) { + std::istringstream iss(line); + int n; + bool safe = true; + int prev = -1; + bool increasing = false, decreasing = false; + // put to vector and pair of two + while (iss >> n) { + if (prev == -1) { + prev = n; + continue; + } + if (prev < n) + increasing = true; + else if (prev > n) + decreasing = true; + if (std::abs(prev - n) > 3 || prev == n || (n > prev && decreasing || n < prev && increasing || increasing && decreasing || !increasing && !decreasing)) { + safe = false; + break; + } + prev = n; + } + if (safe) { + res++; + } + } + + // print + std::cout << res << std::endl; +}
\ No newline at end of file |
