From: Skullheadx Date: Thu, 2 Feb 2023 19:31:55 +0000 (-0500) Subject: 2020 S3 CPP X-Git-Url: http://git.skullheadx.com/nixos/tech/openbsd_html_css/post.html?a=commitdiff_plain;h=1fce28f560b6b3d4b8a7d430e04781f09b8953ad;p=CCC.git 2020 S3 CPP --- diff --git a/.idea/CCC.iml b/.idea/CCC.iml index 7efdecd..a3fe4f9 100644 --- a/.idea/CCC.iml +++ b/.idea/CCC.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index a4652f3..2d0cc4f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/Main/C++/2020/S3.cpp b/Main/C++/2020/S3.cpp new file mode 100644 index 0000000..7a4f948 --- /dev/null +++ b/Main/C++/2020/S3.cpp @@ -0,0 +1,79 @@ +#include +using namespace std; +//template +//void print_map(std::unordered_map 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 seen; + unordered_map 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 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 index 0000000..482f50f --- /dev/null +++ b/Main/Python/2020/S3.py @@ -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 index 0000000..3a85fb5 --- /dev/null +++ b/Main/Python/2020/all_data/junior_data/j1/README.txt @@ -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 index 0000000..9a70759 --- /dev/null +++ b/Main/Python/2020/all_data/junior_data/j2/README.txt @@ -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 index 0000000..9c9e6fe --- /dev/null +++ b/Main/Python/2020/all_data/junior_data/j5_s2/README.txt @@ -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 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 index 0000000..58c1677 --- /dev/null +++ b/Main/Python/2020/senior_data/s5/fix.py @@ -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() + diff --git a/Main/Python/grader.py b/Main/Python/grader.py index 268564e..5802dbd 100644 --- a/Main/Python/grader.py +++ b/Main/Python/grader.py @@ -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