Browse Source

增加部分题目,删除错误的题目

Pchen. 10 months ago
parent
commit
5495c9bdeb
52 changed files with 123 additions and 264 deletions
  1. 0 0
      code/sort-指针例子.c
  2. 0 0
      code/乒乓球比赛.c
  3. 0 0
      code/交换a和b的数值.c
  4. 0 0
      code/从文件data.txt读入若干实数并将统计结果存入文件result.txt中.c
  5. 0 0
      code/使用数组管理学生成绩.c
  6. 0 0
      code/分数化简.c
  7. 0 0
      code/删除子串.c
  8. 0 0
      code/删除字符串中指定n个字符.c
  9. 0 0
      code/判断矩阵.c
  10. 0 59
      code/加强训练任务/合并有序数组.c
  11. 0 70
      code/加强训练任务/合数分解.c
  12. 0 38
      code/加强训练任务/字符查找.c
  13. 0 47
      code/加强训练任务/排序-sort指针例子.c
  14. 0 25
      code/加强训练任务/最大公约数和最小公倍数.c
  15. 0 25
      code/加强训练任务/计算过道和栏杆的造价.c
  16. 0 0
      code/反弹.c
  17. 0 0
      code/各位数字之和.c
  18. 90 0
      code/合数分解.c
  19. 0 0
      code/合数分解1.c
  20. 0 0
      code/四舍五入.c
  21. 0 0
      code/回文数.c
  22. 0 0
      code/字符串中整数.c
  23. 0 0
      code/字符串拼接.c
  24. 0 0
      code/字符串转换成十进制整数.c
  25. 0 0
      code/学生总成绩排序.c
  26. 0 0
      code/小数分数转换.c
  27. 0 0
      code/换钱交易.c
  28. 0 0
      code/换钱的交易.c
  29. 0 0
      code/搬砖问题.c
  30. 0 0
      code/整数三位分节.c
  31. 0 0
      code/整数的n进制字符串表示.c
  32. 0 0
      code/整数组合.c
  33. 0 0
      code/日期天数转换.c
  34. 0 0
      code/根据给定条件,求x^3+y^3.c
  35. 0 0
      code/求A,B.c
  36. 0 0
      code/求cosx计算公式.c
  37. 0 0
      code/用函数嵌套调用实现回文数.c
  38. 0 0
      code/用函数嵌套调用实现回文数的输出.c
  39. 0 0
      code/矩阵运算.c
  40. 0 0
      code/给一个整型数组编号b.c
  41. 0 0
      code/统计两个一维数组a和b中元素的关系.c
  42. 0 0
      code/统计两个一维数组中a和b的关系.c
  43. 0 0
      code/计算公式b.c
  44. 33 0
      code/计算过道和栏杆的造价.c
  45. 0 0
      code/转换整数.c
  46. 0 0
      code/输入年月日求第几天.c
  47. 0 0
      code/输入秒数转换成几分几秒.c
  48. 0 0
      code/连续正整数的和.c
  49. 0 0
      code/限定条件求x3+y3.c
  50. 0 0
      code/项目二第1题-整数交换.c
  51. 0 0
      code/项目二第2题-计算分秒.c
  52. 0 0
      code/项目二第3题-三位整数按位求和.c

+ 0 - 0
code/加强训练任务/sort-指针例子.c → code/sort-指针例子.c


+ 0 - 0
code/加强训练任务/乒乓球比赛.c → code/乒乓球比赛.c


+ 0 - 0
code/加强训练任务/交换a和b的数值.c → code/交换a和b的数值.c


+ 0 - 0
code/加强训练任务/从文件data.txt读入若干实数并将统计结果存入文件result.txt中.c → code/从文件data.txt读入若干实数并将统计结果存入文件result.txt中.c


+ 0 - 0
code/加强训练任务/使用数组管理学生成绩.c → code/使用数组管理学生成绩.c


+ 0 - 0
code/加强训练任务/分数化简.c → code/分数化简.c


+ 0 - 0
code/加强训练任务/删除子串.c → code/删除子串.c


+ 0 - 0
code/加强训练任务/删除字符串中指定n个字符.c → code/删除字符串中指定n个字符.c


+ 0 - 0
code/加强训练任务/判断矩阵.c → code/判断矩阵.c


+ 0 - 59
code/加强训练任务/合并有序数组.c

@@ -1,59 +0,0 @@
-#include <stdio.h>
-
-// Function to merge two sorted arrays into one sorted array
-void mergeSortedArrays(int arr1[], int size1, int arr2[], int size2) {
-    int merged[size1 + size2]; // Result array to store merged sorted elements
-    int i = 0, j = 0, k = 0;   // i for arr1, j for arr2, k for merged array
-
-    // Merge the arrays while both arrays have elements
-    while (i < size1 && j < size2) {
-        if (arr1[i] <= arr2[j]) {
-            merged[k++] = arr1[i++];
-        } else {
-            merged[k++] = arr2[j++];
-        }
-    }
-
-    // If there are remaining elements in arr1, add them to merged array
-    while (i < size1) {
-        merged[k++] = arr1[i++];
-    }
-
-    // If there are remaining elements in arr2, add them to merged array
-    while (j < size2) {
-        merged[k++] = arr2[j++];
-    }
-
-    // Print the merged sorted array
-    int m;
-    for (m = 0; m < size1 + size2; m++) {
-        if (m > 0) {
-            printf(" ");
-        }
-        printf("%d", merged[m]);
-    }
-    printf("\n");
-}
-
-int main() {
-    int size1, size2;
-
-    // Input the first sorted array
-    scanf("%d", &size1);
-    int arr1[size1], i;
-    for (i = 0; i < size1; i++) {
-        scanf("%d", &arr1[i]);
-    }
-
-    // Input the second sorted array
-    scanf("%d", &size2);
-    int arr2[size2];
-    for (i = 0; i < size2; i++) {
-        scanf("%d", &arr2[i]);
-    }
-
-    // Merge and print the sorted arrays
-    mergeSortedArrays(arr1, size1, arr2, size2);
-
-    return 0;
-}

+ 0 - 70
code/加强训练任务/合数分解.c

@@ -1,70 +0,0 @@
-#include <stdio.h>
-#include <stdbool.h>
-
-// 判断一个数是否为素数
-bool isPrime(int num) {
-    if (num <= 1) return false;
-    if (num <= 3) return true;
-    if (num % 2 == 0 || num % 3 == 0) return false;
-    int  i;
-    for (i = 5; i * i <= num; i += 6) {
-        if (num % i == 0 || num % (i + 2) == 0)
-            return false;
-    }
-    return true;
-}
-
-// 打印素数分解结果的最小素数集
-void printMinimumPrimeSet(int *compositeNumbers, int numCount) {
-    // 使用集合来存储最小素数集,利用集合的自动去重和排序特性
-    bool primeSet[100000] = { false }; // 使用一个足够大的数组来存储素数集合
-    int maxNum = 0;
-
-    // 找出所有的素数因子
-    int i, k;
-    for (k = 0; k < numCount; ++k) {
-        int num = compositeNumbers[k];
-        if (isPrime(num)) {
-            primeSet[num] = true;
-            if (num > maxNum) maxNum = num;
-        } else {
-            int factor = 2;
-            while (num > 1) {
-                if (isPrime(factor) && num % factor == 0) {
-                    primeSet[factor] = true;
-                    num /= factor;
-                    factor = 2; // 重新从最小素数开始找因子
-                } else {
-                    factor++;
-                }
-            }
-            if (factor > maxNum) maxNum = factor;
-        }
-    }
-
-    // 输出最小素数集,按从小到大顺序输出
-    bool first = true;
-    for (i = 2; i <= maxNum; ++i) {
-        if (primeSet[i]) {
-            if (!first) printf(" ");
-            printf("%d", i);
-            first = false;
-        }
-    }
-    printf("\n");
-}
-
-int main() {
-    int numCount;
-    scanf("%d", &numCount);
-
-    int compositeNumbers[20];
-    int i;
-    for (i = 0; i < numCount; ++i) {
-        scanf("%d", &compositeNumbers[i]);
-    }
-
-    printMinimumPrimeSet(compositeNumbers, numCount);
-
-    return 0;
-}

+ 0 - 38
code/加强训练任务/字符查找.c

@@ -1,38 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-
-int main() {
-    char str[100];
-    char ch;
-    int count[100];
-    int pos = 0;
-    int flag = 0;
-    int i;
-
-    fgets(str, 100, stdin);
-    scanf("%c", &ch);
-
-    int len = strlen(str);
-    int ch_count = 0;
-
-    for (i = 0; i < len; i++) {
-        if (str[i] == ch) {
-            count[ch_count + 1] = i;
-            ch_count++;
-            flag = 1;
-        }
-    }
-
-    if (flag) {
-        count[0] = ch_count;
-        printf("%d\n", count[0]);
-        for (i = 1; i <= ch_count; i++) {
-            printf("%d ", count[i]);
-        }
-        printf("\n");
-    } else {
-        printf("No match!\n");
-    }
-
-    return 0;
-}

+ 0 - 47
code/加强训练任务/排序-sort指针例子.c

@@ -1,47 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h> // 为了使用 qsort 函数
-#include <math.h>   // 为了使用 fabs 函数
-
-// 比较函数:按照绝对值从大到小排序
-int compare(const void *a, const void *b) {
-    float abs_a = fabs(*(const float *)a);
-    float abs_b = fabs(*(const float *)b);
-    if (abs_a < abs_b) return 1;   // 注意这里是从大到小排序
-    if (abs_a > abs_b) return -1;
-    return 0;
-}
-
-int main() {
-    float *nums;
-    int n = 10; // 输入的数目为 10
-
-    // 动态分配内存来存储输入的浮点数
-    nums = (float *)malloc(n * sizeof(float));
-    if (nums == NULL) {
-        fprintf(stderr, "Memory allocation failed.\n");
-        return 1;
-    }
-
-    // 输入10个浮点数
-    int i;
-    for (i = 0; i < n; ++i) {
-        scanf("%f", &nums[i]);
-    }
-
-    // 使用 qsort 函数对数组进行排序,使用绝对值从大到小排序
-    qsort(nums, n, sizeof(float), compare);
-
-    // 输出排序后的结果,每个数保留小数点后两位有效数字
-    for (i = 0; i < n; ++i) {
-        printf("%.2f", nums[i]);
-        if (i < n - 1) {
-            printf(",");
-        }
-    }
-    printf("\n");
-
-    // 释放动态分配的内存
-    free(nums);
-
-    return 0;
-}

+ 0 - 25
code/加强训练任务/最大公约数和最小公倍数.c

@@ -1,25 +0,0 @@
-#include <stdio.h>
-
-int gcd(int a, int b) {
-    if (b == 0) {
-        return a;
-    }
-    return gcd(b, a % b);
-}
-
-int lcm(int a, int b) {
-    return a / gcd(a, b) * b;
-}
-
-int main() {
-    int a, b;
-
-    scanf("%d %d", &a, &b);
-    
-    int greatest_common_divisor = gcd(a, b);
-    int least_common_multiple = lcm(a, b);
-
-    printf("%d %d\n", greatest_common_divisor, least_common_multiple);
-
-    return 0;
-}

+ 0 - 25
code/加强训练任务/计算过道和栏杆的造价.c

@@ -1,25 +0,0 @@
-#include <stdio.h>
-
-int main() {
-    double radius, pool_area, outer_radius, fence_cost, pathway_cost;
-
-    const double PI = 3.14159;
-    const double fence_price_per_meter = 55.0;
-    const double pathway_price_per_sqm = 40.0;
-    const double pathway_width = 3.0;
-
-    scanf("%lf", &radius);
-
-    pool_area = PI * radius * radius;
-
-    outer_radius = radius + pathway_width;
-
-    fence_cost = 2 * PI * outer_radius * fence_price_per_meter+1;
-
-    double pathway_area = PI * outer_radius * outer_radius - pool_area;
-    pathway_cost = pathway_area * pathway_price_per_sqm+1;
-
-    printf("%d %d\n", (int)pathway_cost, (int)fence_cost);
-
-    return 0;
-}

+ 0 - 0
code/加强训练任务/反弹.c → code/反弹.c


+ 0 - 0
code/加强训练任务/各位数字之和.c → code/各位数字之和.c


+ 90 - 0
code/合数分解.c

@@ -0,0 +1,90 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+#define MAX_N 20
+
+// 函数:检查一个数是否是素数
+bool is_prime(int n) {
+    if (n <= 1) return false;
+    if (n == 2) return true;
+    if (n % 2 == 0) return false;
+    int i;
+    for (i = 3; i * i <= n; i += 2) {
+        if (n % i == 0) return false;
+    }
+    return true;
+}
+
+// 函数:对一个数进行质因数分解,并将结果存入集合
+void factorize(int n, int* primes, int* prime_count) {
+	int i;
+    for (i = 2; i * i <= n; i++) {
+        if (n % i == 0) {
+            while (n % i == 0) {
+                n /= i;
+            }
+            primes[(*prime_count)++] = i;
+        }
+    }
+    if (n > 1) {
+        primes[(*prime_count)++] = n;
+    }
+}
+
+// 函数:对集合中的质因数进行去重
+void remove_duplicates(int* primes, int* prime_count) {
+    bool unique[MAX_N * 20] = {0};
+    int temp[MAX_N * 20];
+    int temp_count = 0;
+    
+    int i;
+    
+    for (i = 0; i < *prime_count; i++) {
+        if (!unique[primes[i]]) {
+            unique[primes[i]] = true;
+            temp[temp_count++] = primes[i];
+        }
+    }
+    
+    for (i = 0; i < temp_count; i++) {
+        primes[i] = temp[i];
+    }
+    
+    *prime_count = temp_count;
+}
+
+// 函数:比较两个整数的比较器,用于qsort函数
+int compare(const void* a, const void* b) {
+    return (*(int*)a - *(int*)b);
+}
+
+int main() {
+    int n;
+    scanf("%d", &n);
+    int i;
+    
+    int numbers[MAX_N];
+    for (i = 0; i < n; i++) {
+        scanf("%d", &numbers[i]);
+    }
+    
+    int primes[MAX_N * 20];
+    int prime_count = 0;
+
+    for (i = 0; i < n; i++) {
+        factorize(numbers[i], primes, &prime_count);
+    }
+
+    remove_duplicates(primes, &prime_count);
+
+    qsort(primes, prime_count, sizeof(int), compare);
+
+    for (i = 0; i < prime_count; i++) {
+        printf("%d ", primes[i]);
+    }
+    printf("\n");
+
+    return 0;
+}
+

+ 0 - 0
code/加强训练任务/合数分解1.c → code/合数分解1.c


+ 0 - 0
code/加强训练任务/四舍五入.c → code/四舍五入.c


+ 0 - 0
code/加强训练任务/回文数.c → code/回文数.c


+ 0 - 0
code/加强训练任务/字符串中整数.c → code/字符串中整数.c


+ 0 - 0
code/加强训练任务/字符串拼接.c → code/字符串拼接.c


+ 0 - 0
code/加强训练任务/字符串转换成十进制整数.c → code/字符串转换成十进制整数.c


+ 0 - 0
code/加强训练任务/学生总成绩排序.c → code/学生总成绩排序.c


+ 0 - 0
code/加强训练任务/小数分数转换.c → code/小数分数转换.c


+ 0 - 0
code/加强训练任务/换钱交易.c → code/换钱交易.c


+ 0 - 0
code/加强训练任务/换钱的交易.c → code/换钱的交易.c


+ 0 - 0
code/加强训练任务/搬砖问题.c → code/搬砖问题.c


+ 0 - 0
code/加强训练任务/整数三位分节.c → code/整数三位分节.c


+ 0 - 0
code/加强训练任务/整数的n进制字符串表示.c → code/整数的n进制字符串表示.c


+ 0 - 0
code/加强训练任务/整数组合.c → code/整数组合.c


+ 0 - 0
code/加强训练任务/日期天数转换.c → code/日期天数转换.c


+ 0 - 0
code/加强训练任务/根据给定条件,求x^3+y^3.c → code/根据给定条件,求x^3+y^3.c


+ 0 - 0
code/加强训练任务/求A,B.c → code/求A,B.c


+ 0 - 0
code/加强训练任务/求cosx计算公式.c → code/求cosx计算公式.c


+ 0 - 0
code/加强训练任务/用函数嵌套调用实现回文数.c → code/用函数嵌套调用实现回文数.c


+ 0 - 0
code/加强训练任务/用函数嵌套调用实现回文数的输出.c → code/用函数嵌套调用实现回文数的输出.c


+ 0 - 0
code/加强训练任务/矩阵运算.c → code/矩阵运算.c


+ 0 - 0
code/加强训练任务/给一个整型数组编号b.c → code/给一个整型数组编号b.c


+ 0 - 0
code/加强训练任务/统计两个一维数组a和b中元素的关系.c → code/统计两个一维数组a和b中元素的关系.c


+ 0 - 0
code/加强训练任务/统计两个一维数组中a和b的关系.c → code/统计两个一维数组中a和b的关系.c


+ 0 - 0
code/加强训练任务/计算公式b.c → code/计算公式b.c


+ 33 - 0
code/计算过道和栏杆的造价.c

@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <math.h>
+
+#define PI 3.14159
+#define FENCE_COST_PER_METER 55
+#define PATH_COST_PER_SQUARE_METER 40
+#define PATH_WIDTH 3
+
+int main() {
+    double pool_radius;
+    double total_radius, fence_cost, path_cost;
+    double pool_area, total_area, path_area;
+
+    scanf("%lf", &pool_radius);
+
+    // 计算总半径(游泳池半径 + 过道宽度)
+    total_radius = pool_radius + PATH_WIDTH;
+
+    // 计算栅栏造价
+    fence_cost = 2 * PI * total_radius * FENCE_COST_PER_METER;
+
+    // 计算过道面积和造价
+    pool_area = PI * pool_radius * pool_radius;
+    total_area = PI * total_radius * total_radius;
+    path_area = total_area - pool_area;
+    path_cost = path_area * PATH_COST_PER_SQUARE_METER;
+
+    // 输出结果,保留整数
+    printf("%d %d\n", (int)round(path_cost), (int)round(fence_cost));
+
+    return 0;
+}
+

+ 0 - 0
code/加强训练任务/转换整数.c → code/转换整数.c


+ 0 - 0
code/加强训练任务/输入年月日求第几天.c → code/输入年月日求第几天.c


+ 0 - 0
code/加强训练任务/输入秒数转换成几分几秒.c → code/输入秒数转换成几分几秒.c


+ 0 - 0
code/加强训练任务/连续正整数的和.c → code/连续正整数的和.c


+ 0 - 0
code/加强训练任务/限定条件求x3+y3.c → code/限定条件求x3+y3.c


+ 0 - 0
code/加强训练任务/项目二第1题-整数交换.c → code/项目二第1题-整数交换.c


+ 0 - 0
code/加强训练任务/项目二第2题-计算分秒.c → code/项目二第2题-计算分秒.c


+ 0 - 0
code/加强训练任务/项目二第3题-三位整数按位求和.c → code/项目二第3题-三位整数按位求和.c