Download benchmarks/Algorithms/concatenating_numbers/solution.c from PV-SJTU/PV-Bench: direct link, hf CLI and curl.
- Browser
- Download file 3.62 kB
-
https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/concatenating_numbers/solution.c
- Command line
-
hf download hf://datasets/PV-SJTU/PV-Bench/benchmarks/Algorithms/concatenating_numbers/solution.c
-
curl -L -o solution.c https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/concatenating_numbers/solution.c
3.62 kB
| void quicksort_numbers(int *numbers, int *lengths, int count, | |
| int number_width, int low, int high) | |
| { | |
| if (0 <= low && low < high && high < count) { | |
| int pivot_length = lengths[high]; | |
| int boundary = low - 1; | |
| int scan; | |
| int pivot; | |
| for (scan = low; scan < high; ++scan) { | |
| int current_length = lengths[scan]; | |
| int total_length = current_length + pivot_length; | |
| int comparison = 0; | |
| int position; | |
| for (position = 0; position < total_length; ++position) { | |
| int left_digit; | |
| int right_digit; | |
| if (position < current_length) { | |
| left_digit = numbers[scan * number_width + position]; | |
| } else { | |
| left_digit = numbers[high * number_width + | |
| (position - current_length)]; | |
| } | |
| if (position < pivot_length) { | |
| right_digit = numbers[high * number_width + position]; | |
| } else { | |
| right_digit = numbers[scan * number_width + | |
| (position - pivot_length)]; | |
| } | |
| if (left_digit != right_digit) { | |
| comparison = left_digit - right_digit; | |
| break; | |
| } | |
| } | |
| if (comparison > 0) { | |
| int column; | |
| int temporary_length; | |
| ++boundary; | |
| for (column = 0; column < number_width; ++column) { | |
| int temporary_digit = | |
| numbers[boundary * number_width + column]; | |
| numbers[boundary * number_width + column] = | |
| numbers[scan * number_width + column]; | |
| numbers[scan * number_width + column] = temporary_digit; | |
| } | |
| temporary_length = lengths[boundary]; | |
| lengths[boundary] = lengths[scan]; | |
| lengths[scan] = temporary_length; | |
| } | |
| } | |
| pivot = boundary + 1; | |
| for (int column = 0; column < number_width; ++column) { | |
| int temporary_digit = | |
| numbers[pivot * number_width + column]; | |
| numbers[pivot * number_width + column] = | |
| numbers[high * number_width + column]; | |
| numbers[high * number_width + column] = temporary_digit; | |
| } | |
| lengths[high] = lengths[pivot]; | |
| lengths[pivot] = pivot_length; | |
| if (pivot > low) { | |
| quicksort_numbers(numbers, lengths, count, number_width, | |
| low, pivot - 1) ; | |
| if (pivot < high) { | |
| quicksort_numbers(numbers, lengths, count, number_width, | |
| pivot + 1, high) ; | |
| } | |
| } else if (pivot < high) { | |
| quicksort_numbers(numbers, lengths, count, number_width, | |
| pivot + 1, high) ; | |
| } | |
| } | |
| } | |
| int* concatenating_numbers(int *numbers, int count, int number_width, | |
| int *lengths, int *result) | |
| { | |
| int result_length = 0; | |
| int i; | |
| if (count > 1) { | |
| quicksort_numbers(numbers, lengths, count, number_width, | |
| 0, count - 1) ; | |
| } | |
| for (i = 0; i < count; ++i) { | |
| int j; | |
| for (j = 0; j < lengths[i]; ++j) { | |
| result[result_length] = numbers[i * number_width + j]; | |
| ++result_length; | |
| } | |
| } | |
| return result; | |
| } | |