Auto commit
This commit is contained in:
parent
195f784173
commit
d06b6fc13d
@ -21,9 +21,22 @@ void fn(char* str){
|
|||||||
p = str;
|
p = str;
|
||||||
q = str;
|
q = str;
|
||||||
/**********Program**********/
|
/**********Program**********/
|
||||||
|
while(*p != '\0'){//p用来遍历所有元素
|
||||||
|
if(*p >= '0' && *p <= '9'){//当前位置指针的元素为数字
|
||||||
|
ch = *p;//备份当前的数字
|
||||||
|
q = p;//q存储当前这个数位置的地址
|
||||||
|
while(q != str){//将p地址前所有的字母整体后移一位
|
||||||
|
//到下一个元素地址为数组首地址或下一个元素为数字时停止
|
||||||
|
if(*(q-1) >='0' && *(q-1) <= '9'){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*q = *(q-1);
|
||||||
|
q--;
|
||||||
|
}
|
||||||
|
*q = ch;
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
}
|
||||||
/********** End **********/
|
/********** End **********/
|
||||||
}
|
}
|
||||||
int main()
|
int main()
|
||||||
|
@ -39,11 +39,16 @@ int calculateDeliveryTimes(int weights[], int size) {
|
|||||||
int deliveryTimes = 1;
|
int deliveryTimes = 1;
|
||||||
|
|
||||||
/**********Program**********/
|
/**********Program**********/
|
||||||
|
int i;
|
||||||
|
for(i=0;i<size;i++){
|
||||||
|
if(weights[i] <= 50){
|
||||||
|
if(currentWeight + weights[i] > 50){
|
||||||
|
currentWeight=0;
|
||||||
|
deliveryTimes++;
|
||||||
|
}
|
||||||
|
currentWeight += weights[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
/********** End **********/
|
/********** End **********/
|
||||||
return deliveryTimes;
|
return deliveryTimes;
|
||||||
}
|
}
|
||||||
@ -67,4 +72,4 @@ int main() {
|
|||||||
printf("需要%d次才能将所有包裹配送完毕。\n", times);
|
printf("需要%d次才能将所有包裹配送完毕。\n", times);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user