]> Skullheadx's Git Forge - CCC.git/commitdiff
2020 S3 CPP
authorSkullheadx <admonty1@gmail.com>
Thu, 2 Feb 2023 19:31:55 +0000 (14:31 -0500)
committerSkullheadx <admonty1@gmail.com>
Thu, 2 Feb 2023 19:31:55 +0000 (14:31 -0500)
.idea/CCC.iml
.idea/misc.xml
Main/C++/2020/S3.cpp [new file with mode: 0644]
Main/Python/2020/S3.py [new file with mode: 0644]
Main/Python/2020/all_data/junior_data/j1/README.txt [new file with mode: 0644]
Main/Python/2020/all_data/junior_data/j2/README.txt [new file with mode: 0644]
Main/Python/2020/all_data/junior_data/j5_s2/README.txt [new file with mode: 0644]
Main/Python/2020/senior_data/s5/.fix.py.swp [new file with mode: 0644]
Main/Python/2020/senior_data/s5/fix.py [new file with mode: 0644]
Main/Python/grader.py

index 7efdecd328a17c536c884ecbc5c9748187a461a1..a3fe4f9401ce578136d15c7f3bce857b3938e3a4 100644 (file)
@@ -5,7 +5,7 @@
       <excludeFolder url="file://$MODULE_DIR$/Main/venv" />
       <excludeFolder url="file://$MODULE_DIR$/venv" />
     </content>
-    <orderEntry type="jdk" jdkName="Python 3.10 (venv)" jdkType="Python SDK" />
+    <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
   </component>
 </module>
\ No newline at end of file
index a4652f355e26c43a58fbff0f10cd661868d00976..2d0cc4fea785aa35326a09a32f4d4d1276d3e54f 100644 (file)
@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
-  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (venv)" project-jdk-type="Python SDK" />
+  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (CCC)" project-jdk-type="Python SDK" />
 </project>
\ No newline at end of file
diff --git a/Main/C++/2020/S3.cpp b/Main/C++/2020/S3.cpp
new file mode 100644 (file)
index 0000000..7a4f948
--- /dev/null
@@ -0,0 +1,79 @@
+#include <bits/stdc++.h>
+using namespace std;
+//template<typename K, typename V>
+//void print_map(std::unordered_map<K, V> const &m)
+//{
+//    for (auto const &pair: m) {
+////        if (pair.second == 0)
+////        {
+////            continue;
+////        }
+//        std::cout << "{" << pair.first << ": " << pair.second << "}\n";
+//    }
+//}
+
+int main()
+{
+    ios_base::sync_with_stdio(false);
+    cin.tie(NULL);
+    string N, H;
+    cin >> N;
+    cin >> H;
+    unordered_map<size_t, bool> seen;
+    unordered_map<char, int> letter_count, needle_count;
+    int x = 0;
+    for(char c : H) {
+
+        needle_count[H[x]] = 0;
+        letter_count[H[x]] = 0;
+        x++;
+    }
+    x = 0;
+        for(char c : N) {
+        needle_count[N[x]] += 1;
+        letter_count[H[x]] += 1;
+        x++;
+    }
+
+    int skip = 0;
+
+    int output = 0;
+    for (int i = N.size() - 1; i < H.size(); i++)
+    {
+        if (i != N.size()-1)
+        {
+            char start = H[i-N.size()];
+            letter_count[start]--;
+            letter_count[H[i]]+=1;
+        }
+
+        if (skip > 0)
+        {
+            skip--;
+            continue;
+        }
+        if (needle_count[H[i]] == 0)
+        {
+            skip = N.size() - 1;
+            continue;
+        }
+
+        string buffer = H.substr(i - N.size() + 1, N.size());
+//        cout << buffer << endl;
+//        print_map(letter_count);
+//        cout<< endl;
+//        print_map(needle_count);
+
+        hash<string> hasher;
+        size_t hash = hasher(buffer);
+
+        if (letter_count == needle_count && !seen[hash])
+        {
+            output++;
+            seen[hash] = true;
+        }
+
+    }
+    cout << output;
+    return 0;
+}
diff --git a/Main/Python/2020/S3.py b/Main/Python/2020/S3.py
new file mode 100644 (file)
index 0000000..482f50f
--- /dev/null
@@ -0,0 +1,35 @@
+N = input()
+H = input()
+
+output = 0
+seen = set()
+
+letter_count = {}
+for i in H[:len(N)]:
+    letter_count[i] = letter_count.get(i, 0) + 1
+
+needle_count = {}
+for i in N:
+    needle_count[i] = needle_count.get(i, 0) + 1
+
+skip = 0
+
+for i in range(len(N)-1, len(H)):
+    if i != len(N) - 1:
+        start = H[i - len(N)]
+        letter_count[start] -= 1
+        if letter_count[start] == 0:
+            del letter_count[start]
+        letter_count[H[i]] = letter_count.get(H[i], 0) + 1
+    if skip > 0:
+        skip -= 1
+        continue
+    if H[i] not in needle_count:
+        skip = len(N) - 1
+        continue
+    buffer = H[i - len(N) + 1:i + 1]
+    if buffer not in seen and letter_count == needle_count:
+        output += 1
+        seen.add(buffer)
+
+print(output)
diff --git a/Main/Python/2020/all_data/junior_data/j1/README.txt b/Main/Python/2020/all_data/junior_data/j1/README.txt
new file mode 100644 (file)
index 0000000..3a85fb5
--- /dev/null
@@ -0,0 +1,4 @@
+Test files j1.04.* refer to Subtask 1
+Test files j1.01.* refer to Subtask 2
+Test files j1.02.* refer to Subtask 3
+Test files j1.03.* refer to Subtask 4
diff --git a/Main/Python/2020/all_data/junior_data/j2/README.txt b/Main/Python/2020/all_data/junior_data/j2/README.txt
new file mode 100644 (file)
index 0000000..9a70759
--- /dev/null
@@ -0,0 +1 @@
+Note that the numbering of these files does not match the numbering of the tests/subtasks in the online grader.
diff --git a/Main/Python/2020/all_data/junior_data/j5_s2/README.txt b/Main/Python/2020/all_data/junior_data/j5_s2/README.txt
new file mode 100644 (file)
index 0000000..9c9e6fe
--- /dev/null
@@ -0,0 +1,3 @@
+Test files j1.05.* refer to Subtask 4
+Test files j1.06.* refer to Subtask 5
+Test files j1.07.* refer to Subtask 6
diff --git a/Main/Python/2020/senior_data/s5/.fix.py.swp b/Main/Python/2020/senior_data/s5/.fix.py.swp
new file mode 100644 (file)
index 0000000..866149b
Binary files /dev/null and b/Main/Python/2020/senior_data/s5/.fix.py.swp differ
diff --git a/Main/Python/2020/senior_data/s5/fix.py b/Main/Python/2020/senior_data/s5/fix.py
new file mode 100644 (file)
index 0000000..58c1677
--- /dev/null
@@ -0,0 +1,16 @@
+import os
+for filename in os.listdir(''):
+    if filename[-2:] == "in":
+        print(filename)
+        f = open(filename)
+        lines = f.readlines()
+        f.close()
+        line1 = lines[0]
+        line2 = " ".join(lines[1:])
+        line2 = line2.replace("\n", "")
+        #print line1+line2
+        f2 = open(filename, "w")
+        f2.write(line1)
+        f2.write(line2+"\n")
+        f2.close()
+
index 268564eadc4eba5d3e568f0613ad9fd5a4402cea..5802dbd793ba49291568ba0e2420ef5b754c194e 100644 (file)
@@ -14,10 +14,10 @@ class Capturing(list):
         sys.stdout = self._stdout
 
 
-PATH = "2012/"
-PROBLEM = "S2"
+PATH = "2020/"
+PROBLEM = "S3"
 
-test_input_path = os.path.join(PATH, f"senior/{PROBLEM}/")
+test_input_path = os.path.join(PATH, f"senior_data/{PROBLEM}/")
 
 test_inputs = []
 test_outputs = []
@@ -32,6 +32,7 @@ for root, dirs, files in os.walk(test_input_path):
 total = min(len(test_inputs), len(test_outputs))
 correct = 0
 
+counter = 1
 for test_input, test_output in zip(test_inputs, test_outputs):
     with Capturing() as output:
         start = time.perf_counter()
@@ -39,14 +40,15 @@ for test_input, test_output in zip(test_inputs, test_outputs):
         end = time.perf_counter()
 
     if "\n".join(output) + "\n" == test_output:
-        print(f"Test Passed. {round(end - start, 3)}s")
+        print(f"Test {counter} Passed. {round(end - start, 3)}s")
         correct += 1
     else:
-        print(f"Test Failed. {round(end - start, 3)}s")
+        print(f"Test {counter} Failed. {round(end - start, 3)}s")
         print(f"{test_input = }")
         print(f"{test_output = }")
         print(f"{output = }")
         print()
+    counter += 1
 
 print("--------------------------------")
 print(f"Tests passed: {correct}/{total}")
\ No newline at end of file