<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
<?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
--- /dev/null
+#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;
+}
--- /dev/null
+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)
--- /dev/null
+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
--- /dev/null
+Note that the numbering of these files does not match the numbering of the tests/subtasks in the online grader.
--- /dev/null
+Test files j1.05.* refer to Subtask 4
+Test files j1.06.* refer to Subtask 5
+Test files j1.07.* refer to Subtask 6
--- /dev/null
+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()
+
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 = []
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()
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