Skip to content

Commit

Permalink
Update on 04/04/2018
Browse files Browse the repository at this point in the history
  • Loading branch information
tsunghsienlee committed Apr 4, 2018
1 parent 407c643 commit c7cb362
Show file tree
Hide file tree
Showing 747 changed files with 61,289 additions and 89 deletions.
2 changes: 1 addition & 1 deletion epi_judge_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.4)
project(epi_judge_cpp)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)

if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -wd4018 -wd4800 -wd4805)
Expand Down
2 changes: 1 addition & 1 deletion epi_judge_cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ TEST_DATA_DIR := ../test_data
PROGRAM_ARGS := --test-data-dir $(TEST_DATA_DIR)

CXX_COMPILER := g++
CXX_FLAGS := -std=c++14 -pthread -Werror
CXX_FLAGS := -std=c++17 -pthread -Werror
CXX_FLAGS_DEBUG := $(CXX_FLAGS) -g -O0

LAST_MODIFIED_CXX_FILE = $(shell ls -rt $(SRC_DIR)/*\.cc | tail -1)
Expand Down
14 changes: 7 additions & 7 deletions epi_judge_cpp/graph_clone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ vector<int> CopyLabels(const vector<GraphVertex*>& edges) {
return labels;
}

void CheckAndDeallocateGraph(GraphVertex* node,
const vector<GraphVertex>& graph) {
if (node == &graph[0]) {
void CheckGraph(GraphVertex* node, const vector<GraphVertex>& graph) {
if (!node || node == &graph[0]) {
throw TestFailure("Graph was not copied");
}

Expand All @@ -41,14 +40,15 @@ void CheckAndDeallocateGraph(GraphVertex* node,
while (!q.empty()) {
auto vertex = q.front();
q.pop();
if (vertex->label > graph.size()) {
if (vertex->label >= graph.size()) {
throw TestFailure("Invalid vertex label");
}
vector<int> label1 = CopyLabels(vertex->edges),
label2 = CopyLabels(graph[vertex->label].edges);
sort(begin(label1), end(label1)), sort(begin(label2), end(label2));
sort(begin(label1), end(label1));
sort(begin(label2), end(label2));
if (label1 != label2) {
throw TestFailure("Invalid vertex label");
throw TestFailure("Edges mismatch");
}
for (GraphVertex* e : vertex->edges) {
if (!vertex_set.count(e)) {
Expand Down Expand Up @@ -88,7 +88,7 @@ void CloneGraphTest(int k, const vector<Edge>& edges) {
graph[e.from].edges.push_back(&graph[e.to]);
}
GraphVertex* result = CloneGraph(&graph[0]);
CheckAndDeallocateGraph(result, graph);
CheckGraph(result, graph);
}

int main(int argc, char* argv[]) {
Expand Down
32 changes: 29 additions & 3 deletions epi_judge_cpp/is_string_decomposable_into_words.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <string>
#include <unordered_set>
#include <vector>

#include "test_framework/generic_test.h"
#include "test_framework/test_failure.h"

using std::string;
using std::unordered_set;
Expand All @@ -13,10 +15,34 @@ vector<string> DecomposeIntoDictionaryWords(
return {};
}

void DecomposeIntoDictionaryWordsWrapper(
TimedExecutor& executor, const string& domain,
const unordered_set<string>& dictionary, bool decomposable) {
vector<string> result = executor.Run(
[&] { return DecomposeIntoDictionaryWords(domain, dictionary); });
if (!decomposable) {
if (!result.empty()) {
throw TestFailure("domain is not decomposable");
}
return;
}

if (std::any_of(std::begin(result), std::end(result),
[&](const std::string& s) { return !dictionary.count(s); })) {
throw TestFailure("Result uses words not in dictionary");
}

if (std::accumulate(std::begin(result), std::end(result), string()) !=
domain) {
throw TestFailure("Result is not composed into domain");
}
}

int main(int argc, char* argv[]) {
std::vector<std::string> args{argv + 1, argv + argc};
std::vector<std::string> param_names{"domain", "dictionary"};
std::vector<std::string> param_names{"executor", "domain", "dictionary",
"decomposable"};
return GenericTestMain(args, "is_string_decomposable_into_words.tsv",
&DecomposeIntoDictionaryWords, DefaultComparator{},
param_names);
&DecomposeIntoDictionaryWordsWrapper,
DefaultComparator{}, param_names);
}
2 changes: 1 addition & 1 deletion epi_judge_cpp/test_framework/test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ std::string GetDefaultTestDataDirPath() {
}

std::string GetFilePathInJudgeDir(const std::string& file_name) {
return GetDefaultTestDataDirPath().insert(0, pardir) + platform::PathSep() + file_name;
return GetDefaultTestDataDirPath() + platform::PathSep() + std::string(pardir) + file_name;
}

/**
Expand Down
224 changes: 224 additions & 0 deletions epi_judge_cpp_solutions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
cmake_minimum_required(VERSION 3.4)
project(epi_judge_cpp)

set(CMAKE_CXX_STANDARD 17)

if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -wd4018 -wd4800 -wd4805)
else()
link_libraries(pthread)
endif()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

add_executable(a_b_sqrt2 a_b_sqrt2.cc)
add_executable(absent_value_array absent_value_array.cc)
add_executable(adding_credits adding_credits.cc)
add_executable(advance_by_offsets advance_by_offsets.cc)
add_executable(alternating_array alternating_array.cc)
add_executable(anagrams anagrams.cc)
add_executable(apply_permutation apply_permutation.cc)
add_executable(arbitrage arbitrage.cc)
add_executable(binomial_coefficients binomial_coefficients.cc)
add_executable(bonus bonus.cc)
add_executable(bst_from_preorder bst_from_preorder.cc)
add_executable(bst_from_sorted_array bst_from_sorted_array.cc)
add_executable(bst_merge bst_merge.cc)
add_executable(bst_to_sorted_list bst_to_sorted_list.cc)
add_executable(buy_and_sell_stock buy_and_sell_stock.cc)
add_executable(buy_and_sell_stock_k_times buy_and_sell_stock_k_times.cc)
add_executable(buy_and_sell_stock_twice buy_and_sell_stock_twice.cc)
add_executable(calendar_rendering calendar_rendering.cc)
add_executable(circular_queue circular_queue.cc)
add_executable(closest_int_same_weight closest_int_same_weight.cc)
add_executable(collatz_checker collatz_checker.cc)
add_executable(combinations combinations.cc)
add_executable(convert_base convert_base.cc)
add_executable(copy_posting_list copy_posting_list.cc)
add_executable(count_bits count_bits.cc)
add_executable(count_inversions count_inversions.cc)
add_executable(deadlock_detection deadlock_detection.cc)
add_executable(defective_jugs defective_jugs.cc)
add_executable(delete_from_list delete_from_list.cc)
add_executable(delete_kth_last_from_list delete_kth_last_from_list.cc)
add_executable(delete_node_from_list delete_node_from_list.cc)
add_executable(descendant_and_ancestor_in_bst descendant_and_ancestor_in_bst.cc)
add_executable(directory_path_normalization directory_path_normalization.cc)
add_executable(do_lists_overlap do_lists_overlap.cc)
add_executable(do_terminated_lists_overlap do_terminated_lists_overlap.cc)
add_executable(drawing_skyline drawing_skyline.cc)
add_executable(dutch_national_flag dutch_national_flag.cc)
add_executable(element_appearing_once element_appearing_once.cc)
add_executable(enumerate_balanced_parentheses enumerate_balanced_parentheses.cc)
add_executable(enumerate_palindromic_decompositions enumerate_palindromic_decompositions.cc)
add_executable(enumerate_trees enumerate_trees.cc)
add_executable(evaluate_rpn evaluate_rpn.cc)
add_executable(even_odd_array even_odd_array.cc)
add_executable(even_odd_list_merge even_odd_list_merge.cc)
add_executable(find_salary_threshold find_salary_threshold.cc)
add_executable(first_missing_positive_entry first_missing_positive_entry.cc)
add_executable(gcd gcd.cc)
add_executable(graph_clone graph_clone.cc)
add_executable(gray_code gray_code.cc)
add_executable(group_equal_entries group_equal_entries.cc)
add_executable(h_index h_index.cc)
add_executable(hanoi hanoi.cc)
add_executable(huffman_coding huffman_coding.cc)
add_executable(insert_in_list insert_in_list.cc)
add_executable(insert_operators_in_string insert_operators_in_string.cc)
add_executable(int_as_array_increment int_as_array_increment.cc)
add_executable(int_as_array_multiply int_as_array_multiply.cc)
add_executable(int_as_list_add int_as_list_add.cc)
add_executable(int_square_root int_square_root.cc)
add_executable(intersect_sorted_arrays intersect_sorted_arrays.cc)
add_executable(interval_add interval_add.cc)
add_executable(intervals_union intervals_union.cc)
add_executable(is_anonymous_letter_constructible is_anonymous_letter_constructible.cc)
add_executable(is_array_dominated is_array_dominated.cc)
add_executable(is_circuit_wirable is_circuit_wirable.cc)
add_executable(is_list_cyclic is_list_cyclic.cc)
add_executable(is_list_palindromic is_list_palindromic.cc)
add_executable(is_number_palindromic is_number_palindromic.cc)
add_executable(is_string_decomposable_into_words is_string_decomposable_into_words.cc)
add_executable(is_string_in_matrix is_string_in_matrix.cc)
add_executable(is_string_palindromic_punctuation is_string_palindromic_punctuation.cc)
add_executable(is_string_permutable_to_palindrome is_string_permutable_to_palindrome.cc)
add_executable(is_tree_a_bst is_tree_a_bst.cc)
add_executable(is_tree_balanced is_tree_balanced.cc)
add_executable(is_tree_symmetric is_tree_symmetric.cc)
add_executable(is_valid_parenthesization is_valid_parenthesization.cc)
add_executable(is_valid_sudoku is_valid_sudoku.cc)
add_executable(k_closest_stars k_closest_stars.cc)
add_executable(k_largest_in_heap k_largest_in_heap.cc)
add_executable(k_largest_values_in_bst k_largest_values_in_bst.cc)
add_executable(knapsack knapsack.cc)
add_executable(kth_largest_element_in_two_sorted_arrays kth_largest_element_in_two_sorted_arrays.cc)
add_executable(kth_largest_in_array kth_largest_in_array.cc)
add_executable(kth_node_in_tree kth_node_in_tree.cc)
add_executable(largest_rectangle_under_skyline largest_rectangle_under_skyline.cc)
add_executable(left_right_justify_text left_right_justify_text.cc)
add_executable(levenshtein_distance levenshtein_distance.cc)
add_executable(line_through_most_points line_through_most_points.cc)
add_executable(list_cyclic_right_shift list_cyclic_right_shift.cc)
add_executable(longest_contained_interval longest_contained_interval.cc)
add_executable(longest_increasing_subarray longest_increasing_subarray.cc)
add_executable(longest_nondecreasing_subsequence longest_nondecreasing_subsequence.cc)
add_executable(longest_subarray_with_distinct_values longest_subarray_with_distinct_values.cc)
add_executable(longest_subarray_with_sum_constraint longest_subarray_with_sum_constraint.cc)
add_executable(longest_substring_with_matching_parentheses longest_substring_with_matching_parentheses.cc)
add_executable(look_and_say look_and_say.cc)
add_executable(lowest_common_ancestor lowest_common_ancestor.cc)
add_executable(lowest_common_ancestor_close_ancestor lowest_common_ancestor_close_ancestor.cc)
add_executable(lowest_common_ancestor_in_bst lowest_common_ancestor_in_bst.cc)
add_executable(lowest_common_ancestor_with_parent lowest_common_ancestor_with_parent.cc)
add_executable(lru_cache lru_cache.cc)
add_executable(majority_element majority_element.cc)
add_executable(matrix_connected_regions matrix_connected_regions.cc)
add_executable(matrix_enclosed_regions matrix_enclosed_regions.cc)
add_executable(matrix_rotation matrix_rotation.cc)
add_executable(max_of_sliding_window max_of_sliding_window.cc)
add_executable(max_product_all_but_one max_product_all_but_one.cc)
add_executable(max_safe_height max_safe_height.cc)
add_executable(max_square_submatrix max_square_submatrix.cc)
add_executable(max_submatrix max_submatrix.cc)
add_executable(max_teams_in_photograph max_teams_in_photograph.cc)
add_executable(max_trapped_water max_trapped_water.cc)
add_executable(max_water_trappable max_water_trappable.cc)
add_executable(maximum_subarray_in_circular_array maximum_subarray_in_circular_array.cc)
add_executable(minimum_distance_3_sorted_arrays minimum_distance_3_sorted_arrays.cc)
add_executable(minimum_points_covering_intervals minimum_points_covering_intervals.cc)
add_executable(minimum_waiting_time minimum_waiting_time.cc)
add_executable(minimum_weight_path_in_a_triangle minimum_weight_path_in_a_triangle.cc)
add_executable(n_queens n_queens.cc)
add_executable(nearest_repeated_entries nearest_repeated_entries.cc)
add_executable(next_permutation next_permutation.cc)
add_executable(nonuniform_random_number nonuniform_random_number.cc)
add_executable(number_of_score_combinations number_of_score_combinations.cc)
add_executable(number_of_traversals_matrix number_of_traversals_matrix.cc)
add_executable(number_of_traversals_staircase number_of_traversals_staircase.cc)
add_executable(offline_sampling offline_sampling.cc)
add_executable(online_median online_median.cc)
add_executable(online_sampling online_sampling.cc)
add_executable(parity parity.cc)
add_executable(pascal_triangle pascal_triangle.cc)
add_executable(path_sum path_sum.cc)
add_executable(permutations permutations.cc)
add_executable(phone_number_mnemonic phone_number_mnemonic.cc)
add_executable(picking_up_coins picking_up_coins.cc)
add_executable(pivot_list pivot_list.cc)
add_executable(power_set power_set.cc)
add_executable(power_x_y power_x_y.cc)
add_executable(pretty_printing pretty_printing.cc)
add_executable(prime_sieve prime_sieve.cc)
add_executable(primitive_divide primitive_divide.cc)
add_executable(primitive_multiply primitive_multiply.cc)
add_executable(queue_from_stacks queue_from_stacks.cc)
add_executable(queue_with_max queue_with_max.cc)
add_executable(random_permutation random_permutation.cc)
add_executable(random_subset random_subset.cc)
add_executable(real_square_root real_square_root.cc)
add_executable(rectangle_intersection rectangle_intersection.cc)
add_executable(refueling_schedule refueling_schedule.cc)
add_executable(regular_expression regular_expression.cc)
add_executable(remove_duplicates remove_duplicates.cc)
add_executable(remove_duplicates_from_sorted_list remove_duplicates_from_sorted_list.cc)
add_executable(replace_and_remove replace_and_remove.cc)
add_executable(reverse_bits reverse_bits.cc)
add_executable(reverse_digits reverse_digits.cc)
add_executable(reverse_sublist reverse_sublist.cc)
add_executable(reverse_words reverse_words.cc)
add_executable(road_network road_network.cc)
add_executable(roman_to_integer roman_to_integer.cc)
add_executable(rook_attack rook_attack.cc)
add_executable(rotate_array rotate_array.cc)
add_executable(run_length_compression run_length_compression.cc)
add_executable(search_entry_equal_to_index search_entry_equal_to_index.cc)
add_executable(search_first_greater_value_in_bst search_first_greater_value_in_bst.cc)
add_executable(search_first_key search_first_key.cc)
add_executable(search_for_min_max_in_array search_for_min_max_in_array.cc)
add_executable(search_for_missing_element search_for_missing_element.cc)
add_executable(search_frequent_items search_frequent_items.cc)
add_executable(search_in_list search_in_list.cc)
add_executable(search_maze search_maze.cc)
add_executable(search_row_col_sorted_matrix search_row_col_sorted_matrix.cc)
add_executable(search_shifted_sorted_array search_shifted_sorted_array.cc)
add_executable(search_unknown_length_array search_unknown_length_array.cc)
add_executable(smallest_nonconstructible_value smallest_nonconstructible_value.cc)
add_executable(smallest_subarray_covering_all_values smallest_subarray_covering_all_values.cc)
add_executable(smallest_subarray_covering_set smallest_subarray_covering_set.cc)
add_executable(snake_string snake_string.cc)
add_executable(sort_almost_sorted_array sort_almost_sorted_array.cc)
add_executable(sort_increasing_decreasing_array sort_increasing_decreasing_array.cc)
add_executable(sort_list sort_list.cc)
add_executable(sorted_array_remove_dups sorted_array_remove_dups.cc)
add_executable(sorted_arrays_merge sorted_arrays_merge.cc)
add_executable(sorted_list_to_bst sorted_list_to_bst.cc)
add_executable(sorted_lists_merge sorted_lists_merge.cc)
add_executable(spiral_ordering_segments spiral_ordering_segments.cc)
add_executable(spreadsheet_encoding spreadsheet_encoding.cc)
add_executable(stack_with_max stack_with_max.cc)
add_executable(string_decompositions_into_dictionary_words string_decompositions_into_dictionary_words.cc)
add_executable(string_integer_interconversion string_integer_interconversion.cc)
add_executable(string_transformability string_transformability.cc)
add_executable(substring_match substring_match.cc)
add_executable(successor_in_tree successor_in_tree.cc)
add_executable(sudoku_solve sudoku_solve.cc)
add_executable(sum_root_to_leaf sum_root_to_leaf.cc)
add_executable(sunset_view sunset_view.cc)
add_executable(swap_bits swap_bits.cc)
add_executable(task_pairing task_pairing.cc)
add_executable(three_sum three_sum.cc)
add_executable(tree_connect_leaves tree_connect_leaves.cc)
add_executable(tree_exterior tree_exterior.cc)
add_executable(tree_from_preorder_inorder tree_from_preorder_inorder.cc)
add_executable(tree_from_preorder_with_null tree_from_preorder_with_null.cc)
add_executable(tree_inorder tree_inorder.cc)
add_executable(tree_level_order tree_level_order.cc)
add_executable(tree_postorder tree_postorder.cc)
add_executable(tree_preorder tree_preorder.cc)
add_executable(tree_right_sibling tree_right_sibling.cc)
add_executable(tree_with_parent_inorder tree_with_parent_inorder.cc)
add_executable(two_sum two_sum.cc)
add_executable(uniform_random_number uniform_random_number.cc)
add_executable(valid_ip_addresses valid_ip_addresses.cc)
add_executable(zip_list zip_list.cc)
Loading

0 comments on commit c7cb362

Please sign in to comment.