Browse Source

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

Pchen. 10 months ago
parent
commit
9fdd11b630
31 changed files with 530 additions and 323 deletions
  1. BIN
      code/加强训练任务/gmon.out
  2. BIN
      code/加强训练任务/交换a和b的数值.exe
  3. 21 26
      code/加强训练任务/反弹.c
  4. 39 28
      code/加强训练任务/合并有序数组.c
  5. 52 61
      code/加强训练任务/合数分解.c
  6. 42 6
      code/加强训练任务/合数分解1.c
  7. BIN
      code/加强训练任务/回文数.exe
  8. 41 24
      code/加强训练任务/字符串转换成十进制整数.c
  9. 0 57
      code/加强训练任务/打印正六边形.c
  10. BIN
      code/加强训练任务/打印正六边形.exe
  11. 0 35
      code/加强训练任务/换码序列的拷贝.c
  12. 26 0
      code/加强训练任务/换钱的交易.c
  13. 47 0
      code/加强训练任务/排序-sort指针例子.c
  14. 0 25
      code/加强训练任务/整数分解为若干项之和.c
  15. BIN
      code/加强训练任务/整数分解为若干项之和.exe
  16. 44 0
      code/加强训练任务/日期天数转换.c
  17. 17 0
      code/加强训练任务/根据给定条件,求x^3+y^3.c
  18. 31 0
      code/加强训练任务/用函数嵌套调用实现回文数的输出.c
  19. 45 19
      code/加强训练任务/给一个整型数组编号b.c
  20. 53 0
      code/加强训练任务/统计两个一维数组a和b中元素的关系.c
  21. 0 23
      code/加强训练任务/编写程序 创建文本文件mul_table.txt其内容为九九乘法表.c
  22. BIN
      code/加强训练任务/编写程序 创建文本文件mul_table.txt其内容为九九乘法表.exe
  23. 0 19
      code/加强训练任务/计算n个a相减.c
  24. BIN
      code/加强训练任务/计算n个a相减.exe
  25. BIN
      code/加强训练任务/计算过道和栏杆的造价.exe
  26. 18 0
      code/加强训练任务/转换整数.c
  27. BIN
      code/加强训练任务/输入秒数转换成几分几秒.exe
  28. BIN
      code/加强训练任务/限定条件求x3+y3.exe
  29. 13 0
      code/加强训练任务/项目二第1题-整数交换.c
  30. 17 0
      code/加强训练任务/项目二第2题-计算分秒.c
  31. 24 0
      code/加强训练任务/项目二第3题-三位整数按位求和.c

BIN
code/加强训练任务/gmon.out


BIN
code/加强训练任务/交换a和b的数值.exe


+ 21 - 26
code/加强训练任务/反弹.c

@@ -2,34 +2,29 @@
 
 
 int main() {
 int main() {
     int n, m;
     int n, m;
-    int i;
-    // 从键盘输入整数n和m
+    
     scanf("%d %d", &n, &m);
     scanf("%d %d", &n, &m);
-
-    // 初始高度为n
-    double height = n;
-    // 总路程
-    double total_distance = 0;
-
-    // 第一次落地
-    total_distance += height;
-    // 反弹至原高度的四分之一
-    height /= 4;
-
-    // 从第二次落地开始,循环m-1次
-    for (i = 1; i < m; ++i) {
-        // 落地
-        total_distance += height;
-        // 反弹至原高度的四分之一
-        height /= 4;
-        // 再次下落
-        total_distance += height;
+    
+    double total_distance = 0.0; // 鎬昏矾绋�
+    double height_after_mth_bounce = n; // 绗琺娆¤惤鍦板悗鐨勯珮搴�
+    
+    // 璁$畻姣忔�钀藉湴鐨勬儏鍐�
+    int i;
+    for (i = 1; i <= m; i++) {
+        // 绗琲娆¤惤鍦版椂鐨勮惤鍦拌窛绂�
+        if (i == 1) {
+            total_distance += n; // 绗�竴娆¤惤鍦版椂鐨勮窛绂�
+        } else {
+            total_distance += height_after_mth_bounce * 2; // 鍔犱笂鍙嶅脊鍜屼笅钀界殑璺濈�
+        }
+        
+        // 璁$畻绗琲娆¤惤鍦板悗鐨勫弽寮归珮搴�
+        height_after_mth_bounce /= 4.0;
     }
     }
-
-    // 输出总路程,保留两位小数
+    
+    // 杈撳嚭缁撴灉锛屼繚鐣欏皬鏁扮偣鍚庝袱浣�
     printf("%.2f\n", total_distance);
     printf("%.2f\n", total_distance);
-    // 输出第m次落地后反弹的高度,保留两位小数
-    printf("%.2f\n", height);
-
+    printf("%.2f\n", height_after_mth_bounce);
+    
     return 0;
     return 0;
 }
 }

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

@@ -1,48 +1,59 @@
 #include <stdio.h>
 #include <stdio.h>
 
 
-int main() {
-    int n1, n2,m;
-    scanf("%d", &n1);
-
-    int arr1[n1];
-    int i;
-    for (i = 0; i < n1; i++) {
-        scanf("%d", &arr1[i]);
-    }
-
-    scanf("%d", &n2);
-
-    int arr2[n2];
-    for (i = 0; i < n2; i++) {
-        scanf("%d", &arr2[i]);
-    }
-
-    int merged[n1 + n2];
-	int j = 0;
-	int k = 0;
-
-    while (i < n1 && j < n2) {
-        if (arr1[i] < arr2[j]) {
+// 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++];
             merged[k++] = arr1[i++];
         } else {
         } else {
             merged[k++] = arr2[j++];
             merged[k++] = arr2[j++];
         }
         }
     }
     }
 
 
-    while (i < n1) {
+    // If there are remaining elements in arr1, add them to merged array
+    while (i < size1) {
         merged[k++] = arr1[i++];
         merged[k++] = arr1[i++];
     }
     }
 
 
-    while (j < n2) {
+    // If there are remaining elements in arr2, add them to merged array
+    while (j < size2) {
         merged[k++] = arr2[j++];
         merged[k++] = arr2[j++];
     }
     }
 
 
-    for (m = 0; m < n1 + n2; m++) {
-        printf("%d", merged[m]);
-        if (m < n1 + n2 - 1) {
+    // Print the merged sorted array
+    int m;
+    for (m = 0; m < size1 + size2; m++) {
+        if (m > 0) {
             printf(" ");
             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;
     return 0;
 }
 }

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

@@ -1,79 +1,70 @@
 #include <stdio.h>
 #include <stdio.h>
-#include <stdlib.h>
+#include <stdbool.h>
 
 
-// 函数:判断一个数是否为素数
-int is_prime(int num) {
-	int i;
-    if (num <= 1) return 0;
-    if (num == 2) return 1;
-    if (num % 2 == 0) return 0;
-    for (i = 3; i * i <= num; i += 2) {
-        if (num % i == 0) return 0;
+// 鍒ゆ柇涓€涓�暟鏄�惁涓虹礌鏁�
+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 1;
+    return true;
 }
 }
 
 
-// 函数:获取一个数的所有素数因子
-void get_prime_factors(int num, int *factors, int *count) {
-    int factor = 2;
-    while (num > 1) {
-        if (num % factor == 0) {
-            factors[*count] = factor;
-            (*count)++;
-            num /= factor;
+// 鎵撳嵃绱犳暟鍒嗚В缁撴灉鐨勬渶灏忕礌鏁伴泦
+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 {
         } else {
-            factor++;
-            while (!is_prime(factor)) {
-                factor++;
+            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;
         }
         }
     }
     }
-}
-
-int main() {
-	int i,j;
-    int num;
-
-    scanf("%d", &num);
 
 
-    if (num <= 1) {
-        printf("输入的数必须大于1且为合数。\n");
-        return 1;
+    // 杈撳嚭鏈€灏忕礌鏁伴泦锛屾寜浠庡皬鍒板ぇ椤哄簭杈撳嚭
+    bool first = true;
+    for (i = 2; i <= maxNum; ++i) {
+        if (primeSet[i]) {
+            if (!first) printf(" ");
+            printf("%d", i);
+            first = false;
+        }
     }
     }
+    printf("\n");
+}
 
 
-    int factors[32];  // 假设最大int的素数因子数量不会超过32个
-    int count = 0;
-
-    get_prime_factors(num, factors, &count);
-
-    int occurrences[32] = {0};  // 用于记录每个素数因子的出现次数
-    int unique_factors[32];     // 记录所有唯一的素数因子
-    int unique_count = 0;
+int main() {
+    int numCount;
+    scanf("%d", &numCount);
 
 
-    for (i = 0; i < count; i++) {
-        int factor = factors[i];
-        int found = 0;
-        for (j = 0; j < unique_count; j++) {
-            if (unique_factors[j] == factor) {
-                occurrences[j]++;
-                found = 1;
-                break;
-            }
-        }
-        if (!found) {
-            unique_factors[unique_count] = factor;
-            occurrences[unique_count] = 1;
-            unique_count++;
-        }
+    int compositeNumbers[20];
+    int i;
+    for (i = 0; i < numCount; ++i) {
+        scanf("%d", &compositeNumbers[i]);
     }
     }
 
 
-    // 输出只出现一次的素数因子
-    for (i = 0; i < unique_count; i++) {
-        if (occurrences[i] == 1) {
-            printf("%d ", unique_factors[i]);
-        }
-    }
-    printf("\n");
+    printMinimumPrimeSet(compositeNumbers, numCount);
 
 
     return 0;
     return 0;
 }
 }

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

@@ -1,15 +1,51 @@
 #include <stdio.h>
 #include <stdio.h>
+#include <math.h>
 
 
-int main() {
-    int num,i;
-    scanf("%d", &num);
+// 函数:判断一个数是否为素数
+int is_prime(int num) {
+    if (num <= 1) return 0; // 0和1不是素数
+    if (num == 2) return 1; // 2是素数
+    if (num % 2 == 0) return 0; // 偶数不是素数
+    
+    // 试除法判断是否为素数
+    int i;
+    for (i = 3; i <= sqrt(num); i += 2) {
+        if (num % i == 0) {
+            return 0; // 能整除则不是素数
+        }
+    }
+    return 1; // 不能整除则是素数
+}
 
 
+// 函数:分解合数,找出只出现一次的素数因子
+void decompose(int num) {
+    if (num <= 1) return; // 小于等于1的数没有素数因子
+    
+    int i;
+    // 试除法分解合数
     for (i = 2; i <= num; i++) {
     for (i = 2; i <= num; i++) {
-        while (num % i == 0) {
-            printf("%d ", i);
-            num /= i;
+        if (num % i == 0 && is_prime(i)) {
+            int count = 0;
+            while (num % i == 0) {
+                num /= i;
+                count++;
+            }
+            if (count == 1) {
+                printf("%d ", i); // 输出只出现一次的素数因子
+            }
         }
         }
     }
     }
+    
+    printf("\n");
+}
 
 
+int main() {
+    int num;
+    
+    scanf("%d", &num);
+    
+    // 分解合数并输出只出现一次的素数因子
+    decompose(num);
+    
     return 0;
     return 0;
 }
 }

BIN
code/加强训练任务/回文数.exe


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

@@ -1,36 +1,53 @@
 #include <stdio.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <ctype.h>
-#include <string.h>
-#include <stdlib.h>
 
 
 int main() {
 int main() {
-    char str[100];
-    fgets(str, 100, stdin);
-
-    // Remove newline character
-    str[strcspn(str, "\n")] = '\0';
-
-    int is_negative = 0;
-    int hex_found = 0;
-    int i;
-    unsigned long long decimal = 0;
-
-    for (i = 0; str[i] != '#'; i++) {
-        if (str[i] == '-') {
-            is_negative = 1;
-        } else if (isxdigit(str[i])) {
-            hex_found = 1;
-            char hex_char = toupper(str[i]);
-            int hex_value = isdigit(hex_char) ? hex_char - '0' : hex_char - 'A' + 10;
-            decimal = decimal * 16 + hex_value;
+    char input[1000]; // 假设输入的字符串长度不超过1000
+    char hex_str[1000]; // 存储提取出的十六进制字符
+    int index = 0; // 记录当前处理的字符位置
+    int negative = 0; // 标记是否存在负号
+
+    // 读取输入直到遇到 #
+    while (1) {
+        char ch = getchar();
+        if (ch == '#') {
+            break;
+        }
+        input[index++] = ch;
+    }
+    input[index] = '\0'; // 在输入末尾加上字符串结束符
+
+    // 判断是否有负号
+    if (input[0] == '-') {
+        negative = 1; // 存在负号
+        index = 1; // 从下一个字符开始处理
+    } else {
+        index = 0; // 没有负号,从第一个字符开始处理
+    }
+
+    int hex_index = 0; // 记录当前提取的十六进制字符位置
+
+    // 遍历输入字符串,提取十六进制字符
+    while (input[index] != '\0') {
+        char ch = toupper(input[index]); // 将字符转换为大写以便统一处理
+        if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F')) {
+            hex_str[hex_index++] = ch; // 是十六进制字符,加入到hex_str中
         }
         }
+        index++;
     }
     }
+    hex_str[hex_index] = '\0'; // 在提取的十六进制字符末尾加上字符串结束符
+
+    // 使用sscanf将十六进制字符串转换为长整型
+    long decimal_value;
+    sscanf(hex_str, "%lx", &decimal_value); // %lx格式将十六进制字符串转换为长整型
 
 
-    if (is_negative) {
-        decimal = -decimal;
+    // 如果存在负号,转换后的数值取负
+    if (negative) {
+        decimal_value = -decimal_value;
     }
     }
 
 
-    printf("%lld\n", decimal);
+    // 输出转换后的十进制数值
+    printf("%ld\n", decimal_value);
 
 
     return 0;
     return 0;
 }
 }

+ 0 - 57
code/加强训练任务/打印正六边形.c

@@ -1,57 +0,0 @@
-#include <stdio.h>
-
-// 打印正六边形的函数
-void printHexagon(int N) {
-	int i,j;
-    if (N < 1) {
-        return;
-    }
-
-    // 上半部分
-    for (i = 0; i < N; i++) {
-        // 打印前导空格
-        for (j = 0; j < N - 1 - i; j++) {
-            printf(" ");
-        }
-        // 打印第一个星号
-        printf("*");
-
-        // 打印中间的空格
-        if (i != 0) {
-            for (j = 0; j < 2 * i - 1; j++) {
-                printf(" ");
-            }
-            // 打印第二个星号
-            printf("*");
-        }
-        printf("\n");
-    }
-
-    // 下半部分
-    for (i = N - 2; i >= 0; i--) {
-        // 打印前导空格
-        for (j = 0; j < N - 1 - i; j++) {
-            printf(" ");
-        }
-        // 打印第一个星号
-        printf("*");
-
-        // 打印中间的空格
-        if (i != 0) {
-            for (j = 0; j < 2 * i - 1; j++) {
-                printf(" ");
-            }
-            // 打印第二个星号
-            printf("*");
-        }
-        printf("\n");
-    }
-}
-
-int main() {
-    int N;
-    printf("请输入正整数N: ");
-    scanf("%d", &N);
-    printHexagon(N);
-    return 0;
-}

BIN
code/加强训练任务/打印正六边形.exe


+ 0 - 35
code/加强训练任务/换码序列的拷贝.c

@@ -1,35 +0,0 @@
-#include <stdio.h>
-
-void escape(char s[], char t[]) {
-    int i, j;
-    for (i = 0, j = 0; t[i] != '\0'; i++) {
-        switch (t[i]) {
-            case '\n':
-                s[j++] = '\\';
-                s[j++] = 'n';
-                break;
-            case '\t':
-                s[j++] = '\\';
-                s[j++] = 't';
-                break;
-            default:
-                s[j++] = t[i];
-                break;
-        }
-    }
-    s[j] = '\0';
-}
-
-int main() {
-    char t[50];
-    char s[100]; // Assuming the escaped string length won't exceed 100
-    
-
-    fgets(t, 50, stdin);
-
-    escape(s, t);
-
-    printf("%s\n", s);
-
-    return 0;
-}

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

@@ -0,0 +1,26 @@
+#include <stdio.h>
+
+int main() {
+    int n;
+    long long stranger_total = 0; // 陌生人总计金额,使用 long long 处理大数
+    long long millionaire_total = 0; // 富翁总计金额,使用 long long 处理大数
+    long long stranger_given = 1; // 第一天陌生人给富翁的金额,从1分钱开始
+    
+    scanf("%d", &n);
+    
+    // 按照规则计算每天的交易金额
+    int day;
+    for (day = 1; day <= n; day++) {
+        // 计算富翁给陌生人的金额,每天固定为10万
+        millionaire_total += 100000;
+        
+        // 累加陌生人给富翁的金额,并且每天翻倍
+        stranger_total += stranger_given;
+        stranger_given *= 2;
+    }
+    
+    // 输出结果,注意题目要求输出整数部分
+    printf("%lld\n%lld\n", millionaire_total, stranger_total);
+    
+    return 0;
+}

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

@@ -0,0 +1,47 @@
+#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>
-
-void find_partitions(int n, int start, int* path, int len) {
-	int i;
-    if (n == 0) {
-        printf("7=");
-        for (i = 0; i < len - 1; i++) {
-            printf("%d+", path[i]);
-        }
-        printf("%d\n", path[len - 1]);
-        return;
-    }
-    for (i = start; i <= n; i++) {
-        path[len] = i;
-        find_partitions(n - i, i, path, len + 1);
-    }
-}
-
-int main() {
-    int n;
-    scanf("%d", &n);
-    int path[30];
-    find_partitions(n, 1, path, 0);
-    return 0;
-}

BIN
code/加强训练任务/整数分解为若干项之和.exe


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

@@ -0,0 +1,44 @@
+#include <stdio.h>
+
+// 函数:判断是否为闰年
+int isLeapYear(int year) {
+    if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
+        return 1; // 是闰年
+    else
+        return 0; // 不是闰年
+}
+
+// 函数:计算给定日期是这一年的第几天
+int dayOfYear(int year, int month, int day) {
+    int daysInMonth[] = {31, 28, 31, 30, 31, 30,
+                         31, 31, 30, 31, 30, 31};
+    int totalDays = 0;
+    
+    // 加上之前月份的天数
+    int m;
+    for (m = 1; m < month; m++) {
+        totalDays += daysInMonth[m - 1];
+        // 对于二月且是闰年,需额外加一天
+        if (m == 2 && isLeapYear(year))
+            totalDays++;
+    }
+    
+    // 加上当前月份的天数
+    totalDays += day;
+    
+    return totalDays;
+}
+
+int main() {
+    int year, month, day;
+    
+    scanf("%d %d %d", &year, &month, &day);
+    
+    // 计算该日期是这一年的第几天
+    int result = dayOfYear(year, month, day);
+    
+    // 输出结果
+    printf("%d\n", result);
+    
+    return 0;
+}

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

@@ -0,0 +1,17 @@
+#include <stdio.h>
+
+int main() {
+    int a, b;
+    double result;
+    
+    // 输入a和b的值
+    scanf("%d %d", &a, &b);
+    
+    // 计算x^3 + y^3的值
+    result = (double)a * (3.0 * b - (double)a * (double)a) / 2.0;
+    
+    // 输出结果
+    printf("%.0f\n", result);
+    
+    return 0;
+}

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

@@ -0,0 +1,31 @@
+#include <stdio.h>
+
+// 函数声明:将一个正整数的各位数字逆序返回
+int InvertSequence(int num) {
+    int reversed = 0;
+    while (num > 0) {
+        reversed = reversed * 10 + num % 10;
+        num /= 10;
+    }
+    return reversed;
+}
+
+// 函数声明:判断一个整数是否为回文数
+int loop(int x) {
+    int reversed = InvertSequence(x);
+    return x == reversed;
+}
+
+int main() {
+    int a, b, i;
+    scanf("%d %d", &a, &b);
+
+    // 输出范围[a, b]之间的所有回文数
+    for (i = a; i <= b; ++i) {
+        if (loop(i)) {
+            printf("%d\n", i);
+        }
+    }
+
+    return 0;
+}

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

@@ -1,29 +1,55 @@
 #include <stdio.h>
 #include <stdio.h>
+#include <stdlib.h> // Include stdlib.h for qsort function
+
+typedef struct {
+    int value;
+    int originalIndex;
+} Element;
+
+// Compare function for sorting elements in descending order
+int compare(const void *a, const void *b) {
+    Element *elem1 = (Element *)a;
+    Element *elem2 = (Element *)b;
+    return elem2->value - elem1->value; // Sort in descending order
+}
 
 
 int main() {
 int main() {
-    int n;
-    int i,j;
+    int n; // Number of elements in the array
     scanf("%d", &n);
     scanf("%d", &n);
-
-    int arr[20];
-    for (i = 0; i < n; i++) {
-        scanf("%d", &arr[i]);
+    
+    Element arr[n]; // Array of elements with original indices
+    
+    // Read elements and store them with their original indices
+    int i;
+    for (i = 0; i < n; ++i) {
+        scanf("%d", &arr[i].value);
+        arr[i].originalIndex = i;
     }
     }
-
-    int count = 1;
-    for (i = 0; i < n; i++) {
-        if (arr[i] != -9999) {
-            for (j = i + 1; j < n; j++) {
-                if (arr[j] == arr[i]) {
-                    arr[j] = -9999;
-                }
-            }
-            printf("%d ", count);
-            count++;
+    
+    // Sort elements in descending order based on value
+    qsort(arr, n, sizeof(Element), compare); // Use qsort from stdlib.h
+    
+    // Array to store the ranks
+    int ranks[n];
+    
+    // Assign ranks
+    ranks[arr[0].originalIndex] = 1; // Start with rank 1 for the largest element
+    for (i = 1; i < n; ++i) {
+        if (arr[i].value == arr[i - 1].value) {
+            ranks[arr[i].originalIndex] = ranks[arr[i - 1].originalIndex];
+        } else {
+            ranks[arr[i].originalIndex] = i + 1; // Assign next rank
+        }
+    }
+    
+    // Output the ranks in the original order
+    for (i = 0; i < n; ++i) {
+        printf("%d", ranks[i]);
+        if (i < n - 1) {
+            printf(" ");
         }
         }
     }
     }
-
     printf("\n");
     printf("\n");
-
+    
     return 0;
     return 0;
 }
 }

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

@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+// 比较函数,用于排序
+int compare(const void *a, const void *b) {
+    return (*(int *)a - *(int *)b);
+}
+
+int main() {
+    int a[10]; // 数组a,无序
+    int b[5];  // 数组b,升序
+    int c[4] = {0}; // 结果数组c,包含4个元素,对应于b的前4个元素之间的区间
+	int i, k;
+
+    // 读取数组a
+    for (i = 0; i < 10; ++i) {
+        scanf("%d", &a[i]);
+    }
+
+    // 读取数组b
+    for (i = 0; i < 5; ++i) {
+        scanf("%d", &b[i]);
+    }
+
+    // 对数组a进行排序
+    qsort(a, 10, sizeof(int), compare);
+    printf("c = ");
+
+    // 遍历数组b的每个区间[b[k], b[k+1]]
+    for (k = 0; k < 4; ++k) {
+        int left = 0;  // 区间开始位置
+        int right = 0; // 区间结束位置
+
+        // 找到大于b[k]的第一个元素位置
+        while (right < 10 && a[right] <= b[k]) {
+            right++;
+        }
+
+        // 统计大于b[k]小于b[k+1]的元素个数
+        while (right < 10 && a[right] < b[k + 1]) {
+            right++;
+            c[k]++;
+        }
+    }
+
+    // 输出结果数组c
+    for (i = 0; i < 4; ++i) {
+        printf("%d ", c[i]);
+    }
+    printf("\n");
+
+    return 0;
+}

+ 0 - 23
code/加强训练任务/编写程序 创建文本文件mul_table.txt其内容为九九乘法表.c

@@ -1,23 +0,0 @@
-#include <stdio.h>
-
-int main() {
-    int i, j;
-
-    // 输出表头
-    printf("      ");
-    for (i = 1; i <= 9; i++) {
-        printf("%4d", i);
-    }
-    printf("\n");
-
-    // 输出九九乘法表
-    for (i = 1; i <= 9; i++) {
-        printf("%4d", i);
-        for (j = 1; j <= 9; j++) {
-            printf("%4d", i * j);
-        }
-        printf("\n");
-    }
-
-    return 0;
-}

BIN
code/加强训练任务/编写程序 创建文本文件mul_table.txt其内容为九九乘法表.exe


+ 0 - 19
code/加强训练任务/计算n个a相减.c

@@ -1,19 +0,0 @@
-#include <stdio.h>
-
-int main() {
-    int a, n;
-    scanf("%d %d", &a, &n);
-
-    int num = 0;
-    int i;
-    long long sum = 0;
-    
-    for (i = 0; i < n; i++) {
-        num = num * 10 + a;
-        sum += num;
-    }
-
-    printf("%lld\n", sum);
-    
-    return 0;
-}

BIN
code/加强训练任务/计算n个a相减.exe


BIN
code/加强训练任务/计算过道和栏杆的造价.exe


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

@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <math.h> // 包含数学库,用于使用round函数
+
+int main() {
+    double num;
+    int rounded_num;
+    
+    // 提示用户输入一个小数
+    scanf("%lf", &num);
+    
+    // 使用round函数进行四舍五入并转换为整数
+    rounded_num = (int)round(num);
+    
+    // 输出结果
+    printf("%d\n", rounded_num);
+    
+    return 0;
+}

BIN
code/加强训练任务/输入秒数转换成几分几秒.exe


BIN
code/加强训练任务/限定条件求x3+y3.exe


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

@@ -0,0 +1,13 @@
+#include <stdio.h>
+
+int main() {
+	int a, b;
+	scanf("a=%d,b=%d", &a, &b);
+	
+	int c = a;
+	a = b;
+	b = c;
+	printf("a=%d,b=%d", a, b);
+	
+	return 0;
+}

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

@@ -0,0 +1,17 @@
+#include <stdio.h>
+
+int main() {
+    int total_seconds, minutes, seconds;
+    
+    // 输入总秒数
+    scanf("%d", &total_seconds);
+    
+    // 计算分钟和秒数
+    minutes = total_seconds / 60;
+    seconds = total_seconds % 60;
+    
+    // 输出转换后的时间
+    printf("%dmin%ds\n", minutes, seconds);
+    
+    return 0;
+}

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

@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+int main() {
+    int number;
+    
+    // 输入一个三位正整数
+	scanf("%d", &number);
+    
+    // 确保输入是一个三位正整数
+    if (number < 100 || number > 999) {
+        return 1;
+    }
+    
+    // 计算各位数字之和
+    int hundreds = number / 100;          // 百位数字
+    int tens = (number / 10) % 10;        // 十位数字
+    int units = number % 10;              // 个位数字
+    int sum = hundreds + tens + units;
+    
+    // 输出结果
+    printf("%d\n", sum);
+    
+    return 0;
+}