Auto commit

This commit is contained in:
smallkun 2025-04-01 09:52:18 +08:00
parent dae819bf03
commit e229bbbb5d
9 changed files with 108 additions and 11 deletions

View File

@ -21,7 +21,16 @@ void fun(int *w, int p, int n)
{ {
int temp[p + 1]; int temp[p + 1];
/**********Program**********/ /**********Program**********/
int i,k=0;
for(i=0;i<p+1;i++){
temp[i] = w[i];
}
for(;i<n;i++){
w[k++]=w[i];
}
for(i=0;k<n;k++){
w[k]=temp[i++];
}
/********** End **********/ /********** End **********/
} }
int main() int main()

View File

@ -29,7 +29,12 @@ char *fun(char input[])
} }
int outputIndex = 0; int outputIndex = 0;
/**********Program**********/ /**********Program**********/
int i;
for(i=0;i<len;i++){
while(input[i]=='['){
}
}
/********** End **********/ /********** End **********/
return output; return output;
} }

View File

@ -16,7 +16,13 @@ int totalBottles(int money)
int boughtBottles = money; int boughtBottles = money;
int newBottles; int newBottles;
/**********Program**********/ /**********Program**********/
totalBottlesDrank= money;
while(boughtBottles > 1){
boughtBottles-=2;
boughtBottles++;
totalBottlesDrank++;
}
return totalBottlesDrank;
/********** End **********/ /********** End **********/
} }
int main() int main()

View File

@ -18,7 +18,24 @@ void fun(int *a, int n)
int second_max_index = 0; int second_max_index = 0;
int i; int i;
/**********Program**********/ /**********Program**********/
for(i=1;i<n;i++){
if(a[i]>a[max_index]){
max_index = i;
}
}
i=a[0];
a[0]=a[max_index];
a[max_index]=i;
second_max_index = 1;
for(i=1;i<n;i++){
if(a[i]>a[second_max_index]){
second_max_index = i;
}
}
i=a[1];
a[1]=a[second_max_index];
a[second_max_index]=i;
/********** End **********/ /********** End **********/
} }
int main() int main()

View File

@ -39,7 +39,35 @@ int computeSymmetricDifference(int A[], int sizeA, int B[], int sizeB, int C[])
{ {
int i = 0, j = 0, k = 0; int i = 0, j = 0, k = 0;
/**********Program**********/ /**********Program**********/
while(i<sizeA){
j=0;
while(j<sizeB){
if(A[i]==B[j]){
break;
}
j++;
}
if(j==sizeB){
C[k++]=A[i];
}
i++;
}
j=i=0;
while(j<sizeB){
i=0;
while(i<sizeA){
if(A[i]==B[j]){
break;
}
i++;
}
if(i==sizeA){
C[k++]=B[j];
}
j++;
}
bubbleSort(C,k);
return k;
/********** End **********/ /********** End **********/
} }
int main() int main()

View File

@ -14,7 +14,17 @@ Z ת
void fun(char *str) void fun(char *str)
{ {
/**********Program**********/ /**********Program**********/
char *p;
p=str;
while(*p != '\0'){
if(*p>='a'&&*p<='z'){
*p=((*p+1)<'z'?(*p+1):'a');
}
if(*p>='A'&&*p<='Z'){
*p=((*p+1)<'Z'?(*p+1):'A');
}
p++;
}
/********** End **********/ /********** End **********/
} }
int main() int main()

View File

@ -12,7 +12,15 @@
int mySqrt(int x) int mySqrt(int x)
{ {
/**********Program**********/ /**********Program**********/
int i;
for(i=1;;i++){
if(i*i==x){
return i;
}
if(i*i>x){
return i-1;
}
}
/********** End **********/ /********** End **********/
} }
int main() int main()

View File

@ -21,7 +21,15 @@ Program-End ֮
bool hasDuplicates(int arr[], int size) bool hasDuplicates(int arr[], int size)
{ {
/**********Program**********/ /**********Program**********/
int i,j;
for(i=0;i<size-1;i++){
for(j=i+1;j<size;j++){
if(arr[i]==arr[j]){
return 1;
}
}
}
return 0;
/********** End **********/ /********** End **********/
} }
int main() int main()

View File

@ -41,14 +41,20 @@ Program-End ֮
#define TANK_CAPACITY 100 // 电池总容量(单位:度) #define TANK_CAPACITY 100 // 电池总容量(单位:度)
#define LOW_FUEL_LIMIT (0.10 * TANK_CAPACITY) // 低电量阈值10% #define LOW_FUEL_LIMIT (0.10 * TANK_CAPACITY) // 低电量阈值10%
#define AVG_CONSUMPTION_PER_100KM 10 // 平均电耗(单位:度/百公里) #define AVG_CONSUMPTION_PER_100KM 10 // 平均电耗(单位:度/百公里)
#define FUEL_CONSUMPTION_PER_KM (AVG_CONSUMPTION_PER_100KM / #define FUEL_CONSUMPTION_PER_KM (AVG_CONSUMPTION_PER_100KM / 100.0) // 每公里电耗(单位:度/公里)
100.0) // 每公里电耗(单位:度/公里)
int checkRefuelStops(int trips[], int count, int results[]) int checkRefuelStops(int trips[], int count, int results[])
{ {
int refuel_count = 0; int refuel_count = 0;
double current_fuel = TANK_CAPACITY; double current_fuel = TANK_CAPACITY;
/**********Program**********/ /**********Program**********/
int i;
for(i=0;i<count;i++){
current_fuel = current_fuel-FUEL_CONSUMPTION_PER_KM*trips[i];
if(current_fuel<=LOW_FUEL_LIMIT){
results[refuel_count++]=i+1;
current_fuel=TANK_CAPACITY - FUEL_CONSUMPTION_PER_KM*trips[i];
}
}
/********** End **********/ /********** End **********/
return refuel_count; return refuel_count;
} }