Auto commit

This commit is contained in:
smallkun 2025-03-31 19:37:23 +08:00
parent 2c6fa871fd
commit 984e4b5848
22 changed files with 662 additions and 12 deletions

View File

@ -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");
}
}

View File

@ -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<n){
if(a[i]!= 0){
k++;
if(k%3 == 0){
a[i] = 0;
count++;
}
}
i=(i+1)%n;
}
return i;
/********** End **********/
}
int main()
@ -25,4 +41,4 @@ int main()
result = josephus(n);
printf("最后留下的是原来第%d 号的那位\n", result);
return 0;
}
}

View File

@ -0,0 +1,48 @@
/*----------------------------------------------------------------------
------------------------------------------------------------------------
fun, : ; n ,
0 p( p,p n-1 )
: 10
10 :1 2 3 4 5 6 7 8 9 10
p (p <= 9): 5
: 7 8 9 10 1 2 3 4 5 6
------------------------------------------------------------------------
main
Program-End
Program-End
----------------------------------------------------------------------*/
#include <stdio.h>
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;
}

View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
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;
}

View File

@ -38,6 +38,11 @@ int sum_of_even(int arr[], int size)
int sum = 0;
int i;
/**********Program**********/
for(i=0;i<size;i++){
if(arr[i]%2 == 0){
sum+=arr[i];
}
}
return sum;
/********** End **********/
}

View File

@ -17,7 +17,15 @@
void fun(char *a)
{
/**********Program**********/
char *p;
p=a;
while(*p == '*'){
p++;
}
while(*p != '\0'){
*(a++) = *(p++);
}
*a = '\0';
/********** End **********/
}
main()

View File

@ -33,6 +33,10 @@ int main()
int isMeetCondition(int num)
{
/**********Program**********/
if(num%3==2&&num%5==3&&num%7==2){
return 1;
}
return 0;
/********** End **********/
}

View File

@ -36,7 +36,16 @@ int isSubstring(char *str1, char *str2)
int len2 = strlen(str2);
int i, j;
/**********Program**********/
for(i=0;i<len1;i++){
j=0;
while(str1[i] == str2[j] && str2[j] != '\0'){
i++;
j++;
}
if(str2[j] == '\0'){
return 1;
}
}
/********** End **********/
return 0;
}

View File

@ -20,7 +20,11 @@ int main()
l = strlen(a);
j = 0;
/**********Program**********/
for(i=0;i<l;i++){
if(a[i]<'0'||a[i]>'9'){
b[j++] = a[i];
}
}
/********** End **********/
b[j] = '\0';
printf("【去掉数字后的字符串为:】");

View File

@ -14,7 +14,13 @@ int del(int str[], int n)
{
int i, j = 1;
/**********Program**********/
for(i=2;i<n;i++){
if(str[i] != str[j]){
str[++j] = str[i];
}
}
j++;
return j;
/********** End **********/
}
int main()

View File

@ -38,6 +38,11 @@ int sum_of_even(int arr[], int size)
int sum = 0;
int i;
/**********Program**********/
for(i=0;i<size;i++){
if(arr[i]%2==0){
sum+= arr[i];
}
}
return sum;
/********** End **********/
}

View File

@ -17,7 +17,19 @@
void fun(char *a)
{
/**********Program**********/
char *p,*q;
p=a;
while(*p == '*'){
p++;
}
for(q=p;q > a;q--){
p=q;
while(*p != '\0'){
*(p-1) = *p;
p++;
}
*(p-1) = '\0';
}
/********** End **********/
}
main()

View File

@ -0,0 +1,39 @@
/*-----------------------------------------------------------------------
-------------------------------------------------------------------------
: mn,mn.,mzxcv,nkh021215468796468765465
: mn,.zxcvkh021546879
-------------------------------------------------------------------------
------------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
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';
}

View File

@ -0,0 +1,36 @@
/*-----------------------------------------------------------------------
-------------------------------------------------------------------------
Enter a decimal number: 2
The binary representation is: 10
-------------------------------------------------------------------------
------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
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);
}

View File

@ -0,0 +1,32 @@
/*-----------------------------------------------------------------------
-------------------------------------------------------------------------
1 : 10
1534
-------------------------------------------------------------------------
------------------------------------------------------------------------*/
#include <stdio.h>
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;
}

View File

@ -0,0 +1,31 @@
/*-----------------------------------------------------------------------
-------------------------------------------------------------------------
: 3
5
-------------------------------------------------------------------------
------------------------------------------------------------------------*/
#include <stdio.h>
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;
}

View File

@ -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 <stdio.h>
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;
}

View File

@ -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 <stdio.h>
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;
}

View File

@ -0,0 +1,29 @@
/*----------------------------------------------------------------------
------------------------------------------------------------------------
fun : (
Z A, z a),
1
: 12345QAZWSXrfvtgb@@@
: 12345RBAXTYsgwuhc@@@
------------------------------------------------------------------------
----------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
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;
}

View File

@ -0,0 +1,38 @@
/*----------------------------------------------------------------------
------------------------------------------------------------------------
C
sqrt
1
: 12
12 : 3
------------------------------------------------------------------------
----------------------------------------------------------------------*/
#include <stdio.h>
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;
}

View File

@ -0,0 +1,64 @@
/*----------------------------------------------------------------------
------------------------------------------------------------------------
C arr size
使 bool main
1 2 3 4 5 5 6 a
------------------------------------------------------------------------
main
Program-End
Program-End
----------------------------------------------------------------------*/
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
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;
}

View File

@ -0,0 +1,94 @@
/*----------------------------------------------------------------------
------------------------------------------------------------------------
100 100
10
600
10% 100×10% = 10
1
5
380 200 390 400 300
3
5
2
4
190 140 110 80
------------------------------------------------------------------------
main
Program-End
Program-End
----------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h> // 引入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;
}