summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2024-12-03 12:23:16 +0800
committerlittleblack111 <littleblack11111@gmail.com>2024-12-03 12:23:16 +0800
commitc05f73f8232f4b0f431a355e0108a2032fb73a6e (patch)
treeaabaa30a92e8d3103634bac50454e13e795a792e
parentfbd3dab9f9c2a84b3f117462b29922d1e03984a6 (diff)
add: 2A.py
-rw-r--r--2024/2A.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/2024/2A.py b/2024/2A.py
new file mode 100644
index 0000000..6604a82
--- /dev/null
+++ b/2024/2A.py
@@ -0,0 +1,26 @@
+res = 0
+
+with open("2.in") as f:
+ for i in f:
+ increasing = False
+ decreasing = False
+ safe = True
+ n = i.split()
+ prev = -1
+ for j in n:
+ j = int(j)
+ if prev == -1:
+ prev = j
+ continue
+ if prev < j:
+ increasing = True
+ elif prev > j:
+ decreasing = True
+ if (abs(prev - j) > 3 or prev == j or (j > prev and decreasing or j < prev and increasing or increasing and decreasing or not increasing and not decreasing)):
+ safe = False
+ # break
+ prev = j
+ if safe:
+ res += 1
+
+print(res)