From 984e4b58480d4a1f730f9b729881dc47ae78e163 Mon Sep 17 00:00:00 2001 From: smallkun Date: Mon, 31 Mar 2025 19:37:23 +0800 Subject: [PATCH] Auto commit --- 万维调考试题源码/1-1.c | 15 ++++++- 万维调考试题源码/1-2.c | 20 ++++++++- 万维调考试题源码/10-1.c | 48 ++++++++++++++++++++ 万维调考试题源码/10-2.c | 48 ++++++++++++++++++++ 万维调考试题源码/2-1.c | 7 ++- 万维调考试题源码/2-2.c | 10 ++++- 万维调考试题源码/3-A-1.c | 6 ++- 万维调考试题源码/3-A-2.c | 11 ++++- 万维调考试题源码/3-B-1.c | 6 ++- 万维调考试题源码/3-B-2.c | 8 +++- 万维调考试题源码/4-1.c | 7 ++- 万维调考试题源码/4-2.c | 14 +++++- 万维调考试题源码/5-1.c | 39 +++++++++++++++++ 万维调考试题源码/5-2.c | 36 +++++++++++++++ 万维调考试题源码/6-1.c | 32 ++++++++++++++ 万维调考试题源码/6-2.c | 31 +++++++++++++ 万维调考试题源码/7-1.c | 37 ++++++++++++++++ 万维调考试题源码/7-2.c | 74 +++++++++++++++++++++++++++++++ 万维调考试题源码/8-1.c | 29 +++++++++++++ 万维调考试题源码/8-2.c | 38 ++++++++++++++++ 万维调考试题源码/9-1.c | 64 +++++++++++++++++++++++++++ 万维调考试题源码/9-2.c | 94 ++++++++++++++++++++++++++++++++++++++++ 22 files changed, 662 insertions(+), 12 deletions(-) create mode 100644 万维调考试题源码/10-1.c create mode 100644 万维调考试题源码/10-2.c create mode 100644 万维调考试题源码/5-1.c create mode 100644 万维调考试题源码/5-2.c create mode 100644 万维调考试题源码/6-1.c create mode 100644 万维调考试题源码/6-2.c create mode 100644 万维调考试题源码/7-1.c create mode 100644 万维调考试题源码/7-2.c create mode 100644 万维调考试题源码/8-1.c create mode 100644 万维调考试题源码/8-2.c create mode 100644 万维调考试题源码/9-1.c create mode 100644 万维调考试题源码/9-2.c diff --git a/万维调考试题源码/1-1.c b/万维调考试题源码/1-1.c index 059ecaa..7aa58d2 100644 --- a/万维调考试题源码/1-1.c +++ b/万维调考试题源码/1-1.c @@ -30,7 +30,18 @@ void fun(int m, int k) int index = 63; result[64] = '\0'; /**********Program**********/ - + while(m>0){ + if(m%k<9){ + result[index--] = m%k +48; + }else{ + result[index--] = m%k -10+65; + } + m/=k; + } + index++; + for(;index <65;index++){ + printf("%c",result[index]); + } /********** End **********/ printf("\n"); -} \ No newline at end of file +} diff --git a/万维调考试题源码/1-2.c b/万维调考试题源码/1-2.c index a572bca..fd5e1c7 100644 --- a/万维调考试题源码/1-2.c +++ b/万维调考试题源码/1-2.c @@ -13,7 +13,23 @@ int josephus(int n) { /**********Program**********/ - + int a[n],i,count = 0,k=0; + i=n-1; + while(i>=0){ + a[i]=1; + i--; + } + while(count +void fun(int *w, int p, int n) +{ + int temp[p + 1]; + /**********Program**********/ + + /********** End **********/ +} +int main() +{ + int n, p; + printf("Ԫصĸ: "); + scanf("%d", &n); + int a[n]; + printf("%d :", n); + for (int i = 0; i < n; i++) + { + scanf("%d", &a[i]); + } + printf("p ֵ (p <= %d): ", n - 1); + scanf("%d", &p); + fun(a, p, n); + printf("ƶΪ: "); + for (int i = 0; i < n; i++) + { + printf("%d ", a[i]); + } + printf("\n"); + return 0; +} diff --git a/万维调考试题源码/10-2.c b/万维调考试题源码/10-2.c new file mode 100644 index 0000000..a75bb47 --- /dev/null +++ b/万维调考试题源码/10-2.c @@ -0,0 +1,48 @@ +/*---------------------------------------------------------------------- +ơ +------------------------------------------------------------------------ +дһ C Գ [ֺСдĸ]Ƕ׵ +£[nx]n Ϊx ΪСдĸʾ x ظ n Σ[nxy] +n Ϊxy ΪСдĸʾ xy ظ n Ρʵ fun +ַ벢ԭʼַ +ʾ1 +Ϲַ[5wh] +ԭʼַwhwhwhwhwh +------------------------------------------------------------------------ +ע⣺Դ¡Ķ `main` иݣ + +Program-End ֮䡣 +Ҫɾ־򲻵÷֡ +Ҫ޸ĻɾProgram-End ֮ݷ򲻵÷֡ +----------------------------------------------------------------------*/ +#include +#include +#include +char *fun(char input[]) +{ + int len = strlen(input); + char *output = (char *)malloc(1000 * sizeof(char)); + if (output == NULL) + { + printf("ڴʧܣ\n"); + return NULL; + } + int outputIndex = 0; + /**********Program**********/ + + /********** End **********/ + return output; +} +int main() +{ + char input[1000]; + printf("Ϲַ\n"); + scanf("%s", input); + char *result = fun(input); + if (result != NULL) + { + printf("ԭʼַ%s\n", result); + free(result); + } + return 0; +} diff --git a/万维调考试题源码/2-1.c b/万维调考试题源码/2-1.c index cbc1b94..595aff4 100644 --- a/万维调考试题源码/2-1.c +++ b/万维调考试题源码/2-1.c @@ -38,6 +38,11 @@ int sum_of_even(int arr[], int size) int sum = 0; int i; /**********Program**********/ - + for(i=0;i'9'){ + b[j++] = a[i]; + } + } /********** End **********/ b[j] = '\0'; printf("ȥַֺΪ"); diff --git a/万维调考试题源码/3-B-2.c b/万维调考试题源码/3-B-2.c index b643db6..1b089fd 100644 --- a/万维调考试题源码/3-B-2.c +++ b/万维调考试题源码/3-B-2.c @@ -14,7 +14,13 @@ int del(int str[], int n) { int i, j = 1; /**********Program**********/ - + for(i=2;i a;q--){ + p=q; + while(*p != '\0'){ + *(p-1) = *p; + p++; + } + *(p-1) = '\0'; + } /********** End **********/ } main() diff --git a/万维调考试题源码/5-1.c b/万维调考试题源码/5-1.c new file mode 100644 index 0000000..7423d48 --- /dev/null +++ b/万维调考试题源码/5-1.c @@ -0,0 +1,39 @@ +/*----------------------------------------------------------------------- +ơ +------------------------------------------------------------------------- +ĿдʵһַɾַеظַȻµ +ַظַһγֵַ +ʾ +һַ: mn,mn.,mzxcv,nkh021215468796468765465 +ȥظַַΪ: mn,.zxcvkh021546879 +------------------------------------------------------------------------- +ע⣺Ķеݣ¶ +------------------------------------------------------------------------*/ +#include +#include +void removeDuplicates(char *str); +int main() +{ + char str[100]; + printf("һַ: "); + fgets(str, sizeof(str), stdin); + str[strcspn(str, "\n")] = 0; + removeDuplicates(str); + printf("ȥظַַΪ: %s\n", str); + return 0; +} +void removeDuplicates(char *str) +{ + int seen[256] = {0}; + int writeIdx = 0; + int i; + int len = strlen(str); + if (str == NULL) + return; + if (len <= 1) + return; + /**********Program**********/ + + /********** End **********/ + str[writeIdx] = '\0'; +} diff --git a/万维调考试题源码/5-2.c b/万维调考试题源码/5-2.c new file mode 100644 index 0000000..b3142b2 --- /dev/null +++ b/万维调考试题源码/5-2.c @@ -0,0 +1,36 @@ +/*----------------------------------------------------------------------- +ơ +------------------------------------------------------------------------- +ĿдʵóȡķһʮĶ + +ʾ +Enter a decimal number: 2 +The binary representation is: 10 +------------------------------------------------------------------------- +------------------------------------------------------------------------*/ +#include +#include +void decimalToBinary(int decimal) +{ + int remainder; + int len = 0; + char binary[32]; + int i; + if (decimal == 0) + { + printf("0"); + return; + } + /**********Program**********/ + + /********** End **********/ + printf("%s\n", binary); +} +int main() +{ + int number; + printf("Enter a decimal number: "); + scanf("%d", &number); + printf("The binary representation is: "); + decimalToBinary(number); +} diff --git a/万维调考试题源码/6-1.c b/万维调考试题源码/6-1.c new file mode 100644 index 0000000..6080637 --- /dev/null +++ b/万维调考试题源码/6-1.c @@ -0,0 +1,32 @@ +/*----------------------------------------------------------------------- +ơ +------------------------------------------------------------------------- +Ŀӵһժɸӣһ룬񫣬ֶһ +ֽʣµӳԵһ룬ֶһԺÿ϶ǰһʣ +µһһֱһٳʱֻʣһˡͨ +Ƴҵһ죬дһ칲ժ˶ӡ +ʾ +ӻʣ1 ӵһ: 10 +ӵһժ1534 +------------------------------------------------------------------------- +ע⣺Ķеݣ¶ +------------------------------------------------------------------------*/ +#include +int countPeaches(int lastDay) +{ + int peaches = 1; + int day; + /**********Program**********/ + + /********** End **********/ +} +int main() +{ + int lastDay; + int totalPeaches; + printf("ӻʣ1 ӵһ: "); + scanf("%d", &lastDay); + totalPeaches = countPeaches(lastDay); + printf("ӵһժ%d \n", totalPeaches); + return 0; +} diff --git a/万维调考试题源码/6-2.c b/万维调考试题源码/6-2.c new file mode 100644 index 0000000..a2280b4 --- /dev/null +++ b/万维调考试题源码/6-2.c @@ -0,0 +1,31 @@ +/*----------------------------------------------------------------------- +ơ +------------------------------------------------------------------------- +ĿһƿˮһԪƿӿԻһƿˮ빺ˮĽд +һԺȶƿˮ +ʾ +빺ˮĽԪ: 3 +ܹԺ 5 ƿˮ +------------------------------------------------------------------------- +ע⣺Ķеݣ¶ +------------------------------------------------------------------------*/ +#include +int totalBottles(int money) +{ + int totalBottlesDrank = 0; + int boughtBottles = money; + int newBottles; + /**********Program**********/ + + /********** End **********/ +} +int main() +{ + int money; + int result; + printf("빺ˮĽԪ: "); + scanf("%d", &money); + result = totalBottles(money); + printf("ܹԺ %d ƿˮ\n", result); + return 0; +} diff --git a/万维调考试题源码/7-1.c b/万维调考试题源码/7-1.c new file mode 100644 index 0000000..591f101 --- /dev/null +++ b/万维调考试题源码/7-1.c @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------- +ơ +------------------------------------------------------------------------ +д fun fun Ĺǣʹ + a[0]еԵ a[1]еԵԵĽ +ԭΪ{3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5}ԵĽΪ9 6 4 1 5 3 2 1 5 3 5 +------------------------------------------------------------------------ +ע⣺Դ¡Ķmain иݣ + +Program-End ֮䡣 +Ҫɾ־򲻵÷֡ +Ҫ޸ĻɾProgram-End ֮ݷ򲻵÷֡ +----------------------------------------------------------------------*/ +#include +void fun(int *a, int n) +{ + int max_index = 0; + int second_max_index = 0; + int i; + /**********Program**********/ + + /********** End **********/ +} +int main() +{ + int arr[] = {3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5}; + int size = sizeof(arr) / sizeof(arr[0]); + int i; + fun(arr, size); + printf("Modified array: "); + for (i = 0; i < size; i++) + { + printf("%d ", arr[i]); + } + printf("\n"); + return 0; +} diff --git a/万维调考试题源码/7-2.c b/万维调考试题源码/7-2.c new file mode 100644 index 0000000..1907a3e --- /dev/null +++ b/万维调考试题源码/7-2.c @@ -0,0 +1,74 @@ +/*---------------------------------------------------------------------- +ơ +------------------------------------------------------------------------ +дC 룬ɼ A B ĶԳƲֻ A ֻ + B ԪأʾȽ A B ΪȻʹ˫ָ +뷨ЧҵǵĶԳƲ +ʾ1 + A ĴС: 5 + A 5 Ԫ: 6 5 4 3 2 + B ĴС: 4 + B 4 Ԫ: 7 6 3 8 + A B ĶԳƲΪ: 2 4 5 7 8 +------------------------------------------------------------------------ +ע⣺Դ¡Ķmain иݣ + +Program-End ֮䡣 +Ҫɾ־򲻵÷֡ +Ҫ޸ĻɾProgram-End ֮ݷ򲻵÷֡ +----------------------------------------------------------------------*/ +#include +void bubbleSort(int arr[], int size) +{ + int i, j; + for (i = 0; i < size - 1; i++) + { + for (j = 0; j < size - i - 1; j++) + { + if (arr[j] > arr[j + 1]) + { + // arr[j] arr[j + 1] + int temp = arr[j]; + arr[j] = arr[j + 1]; + arr[j + 1] = temp; + } + } + } +} +int computeSymmetricDifference(int A[], int sizeA, int B[], int sizeB, int C[]) +{ + int i = 0, j = 0, k = 0; + /**********Program**********/ + + /********** End **********/ +} +int main() +{ + int sizeA, sizeB; + int i; + printf(" A ĴС: "); + scanf("%d", &sizeA); + int A[100]; + printf(" A %d Ԫ: ", sizeA); + for (i = 0; i < sizeA; i++) + { + scanf("%d", &A[i]); + } + printf(" B ĴС: "); + scanf("%d", &sizeB); + int B[100]; + printf(" B %d Ԫ: ", sizeB); + for (i = 0; i < sizeB; i++) + { + scanf("%d", &B[i]); + } + int C[200]; // 󳤶Ϊ 200Ϊ A B ֮ + int diffSize = computeSymmetricDifference(A, sizeA, B, sizeB, C); + printf(" A B ĶԳƲΪ: "); + for (i = 0; i < diffSize; i++) + { + printf("%d ", C[i]); + } + printf("\n"); + return 0; +} diff --git a/万维调考试题源码/8-1.c b/万维调考试题源码/8-1.c new file mode 100644 index 0000000..828b2a6 --- /dev/null +++ b/万维调考试题源码/8-1.c @@ -0,0 +1,29 @@ +/*---------------------------------------------------------------------- +ơ +------------------------------------------------------------------------ + fun Ĺ: ַеĸתΪĸеĺĸ( +Z תΪ A, z תΪ a),ַ䣬תַ +ʾ1 +һַ: 12345QAZWSXrfvtgb@@@ +תַΪ: 12345RBAXTYsgwuhc@@@ +------------------------------------------------------------------------ +----------------------------------------------------------------------*/ +#include +#include +#include +void fun(char *str) +{ + /**********Program**********/ + + /********** End **********/ +} +int main() +{ + char input[100]; + printf("һַ: "); + fgets(input, sizeof(input), stdin); + input[strcspn(input, "\n")] = '\0'; + fun(input); + printf("תַΪ: %s\n", input); + return 0; +} diff --git a/万维调考试题源码/8-2.c b/万维调考试题源码/8-2.c new file mode 100644 index 0000000..09087d6 --- /dev/null +++ b/万维调考试题源码/8-2.c @@ -0,0 +1,38 @@ +/*---------------------------------------------------------------------- +ơ +------------------------------------------------------------------------ +Ҫдһƽ֣ C Ա׼ +е sqrt ֽ +ʾ1 +һǸ: 12 +12 ƽ: 3 +------------------------------------------------------------------------ +----------------------------------------------------------------------*/ +#include +int mySqrt(int x) +{ + /**********Program**********/ + + /********** End **********/ +} +int main() +{ + int num; + while (1) + { + printf("һǸ: "); + if (scanf("%d", &num) != 1 || num < 0) + { + while (getchar() != '\n') + ; + printf("ЧһǸ\n"); + } + else + { + break; + } + } + int sqrtResult = mySqrt(num); + printf("%d ƽ: %d\n", num, sqrtResult); + return 0; +} diff --git a/万维调考试题源码/9-1.c b/万维调考试题源码/9-1.c new file mode 100644 index 0000000..e8a2d70 --- /dev/null +++ b/万维调考试题源码/9-1.c @@ -0,0 +1,64 @@ +/*---------------------------------------------------------------------- +ơ +------------------------------------------------------------------------ +дһ C Ժһ arr Լij size Ϊ +ʹ bool ͷظǷظԪء main У +ַʾøúݷؽӦ +ʾϢ +ʾ +ַ룩1 2 3 4 5 5 6 a +дظԪء +------------------------------------------------------------------------ +ע⣺Դ¡Ķ main иݣ + +Program-End ֮䡣 +Ҫɾ־򲻵÷֡ +Ҫ޸ĻɾProgram-End ֮ݷ򲻵÷֡ +----------------------------------------------------------------------*/ +#include +#include +#include +bool hasDuplicates(int arr[], int size) +{ + /**********Program**********/ + + /********** End **********/ +} +int main() +{ + int capacity = 10; + int *arr = (int *)malloc(capacity * sizeof(int)); + if (arr == NULL) + { + printf("ڴʧܣ\n"); + return 1; + } + int size = 0; + int num; + printf("ַ룩"); + while (scanf("%d", &num) == 1) + { + if (size == capacity) + { + capacity *= 2; + arr = (int *)realloc(arr, capacity * sizeof(int)); + if (arr == NULL) + { + printf("ڴʧܣ\n"); + return 1; + } + } + arr[size++] = num; + } + while (getchar() != '\n'); + if (hasDuplicates(arr, size)) + { + printf("дظԪء\n"); + } + else + { + printf("вظԪء\n"); + } + free(arr); + return 0; +} diff --git a/万维调考试题源码/9-2.c b/万维调考试题源码/9-2.c new file mode 100644 index 0000000..5b8f207 --- /dev/null +++ b/万维调考试题源码/9-2.c @@ -0,0 +1,94 @@ +/*---------------------------------------------------------------------- +ơ +------------------------------------------------------------------------ +һλҪʻһ̨綯Ħгȥɶ̡̨綯Ħгĵ +ص洢 + 100 ȵŶһƵƽģҲÿʻ 100 ͻ + 10 +硣иҪǰҪμѽÿһ̵ľ붼С 600 +Ŷ +ÿγʱ򣬵綯Ħгĵضdz״̬ءһؼĹ +ע +Ŷ綯Ħгijصֲ֮鿴ֵʣĵڵ +ܵ + 10%Ҳ 10010% = 10 ȵ߸ʱͱ +ط +Ħгأæһ£ʻԱеļǰҪ +ġ +ʾ1 +̶ +5 +̾룬λ +380 200 390 400 300 +Ҫ¼ǰ磺 + 3 ǰ + 5 ǰ +ʾ2 +̶ +4 +̾룬λ +190 140 110 80 +硣 +------------------------------------------------------------------------ +ע⣺Դ¡Ķ main иݣ + +Program-End ֮䡣 +Ҫɾ־򲻵÷֡ +Ҫ޸ĻɾProgram-End ֮ݷ򲻵÷֡ +----------------------------------------------------------------------*/ +#include +#include // stdlib.h ڶ̬ڴز +#define TANK_CAPACITY 100 // λȣ +#define LOW_FUEL_LIMIT (0.10 * TANK_CAPACITY) // ͵ֵ10% +#define AVG_CONSUMPTION_PER_100KM 10 // ƽģλ/ٹ +#define FUEL_CONSUMPTION_PER_KM (AVG_CONSUMPTION_PER_100KM / +100.0) // ÿģλ/ +int checkRefuelStops(int trips[], int count, int results[]) +{ + int refuel_count = 0; + double current_fuel = TANK_CAPACITY; + /**********Program**********/ + + /********** End **********/ + return refuel_count; +} +int main() +{ + int num_trips; + printf("̶\n"); + scanf("%d", &num_trips); + int *trips = (int *)malloc(num_trips * sizeof(int)); + if (trips == NULL) + { + printf("ڴʧܣ\n"); + return 1; + } + printf("̾룬λ\n"); + for (int i = 0; i < num_trips; ++i) + { + scanf("%d", &trips[i]); + } + int *results = (int *)malloc(num_trips * sizeof(int)); + if (results == NULL) + { + printf("ڴʧܣ\n"); + free(trips); + return 1; + } + int refuel_count = checkRefuelStops(trips, num_trips, results); + if (refuel_count > 0) + { + printf("Ҫ¼ǰ磺\n"); + for (int i = 0; i < refuel_count; i++) + { + printf(" %d ǰ\n", results[i]); + } + } + else + { + printf("硣\n"); + } + free(trips); + free(results); + return 0; +}