Сделал 22 Задание Массивов
This commit is contained in:
parent
c3182c8c24
commit
5852a9f034
23 changed files with 99 additions and 31 deletions
18
WorkingArrays/15Ex/replace_local_min.c
Normal file
18
WorkingArrays/15Ex/replace_local_min.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include "replace_local_min.h"
|
||||
|
||||
int replaceLocalMin(double * numbers) {
|
||||
int length = numbers[0];
|
||||
unsigned final_num = 1;
|
||||
unsigned local_length = 1;
|
||||
|
||||
for (int i = 2; i < length; ++i, ++final_num) {
|
||||
if (numbers[i - 1] == numbers[i]) { if (local_length) ++local_length;
|
||||
} else if (numbers[i - 1] < numbers[i]) {
|
||||
if (local_length) final_num -= (local_length - 1), local_length = 0;
|
||||
} else local_length = 1;
|
||||
}
|
||||
|
||||
if ((numbers[length - 1] == numbers[length - 2]) && (local_length)) final_num -= (local_length - 1);
|
||||
|
||||
return final_num;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue