266 lines
4.4 KiB
C
266 lines
4.4 KiB
C
#include "Function.h"
|
|
|
|
int arr[DEFAULT_LENGHT];
|
|
int lenght = 0;
|
|
|
|
Element getMax(), getMin();
|
|
|
|
//13
|
|
void setArray() {
|
|
printf("n = ");
|
|
scanf_s("%d", &lenght);
|
|
|
|
printf("Ââåäèòå %d ÷èñåë: ", lenght);
|
|
for (int i = 0; i < lenght; i++) {
|
|
scanf_s("%d", &arr[i]);
|
|
}
|
|
}
|
|
|
|
void oddX10() {
|
|
for (int i = 0; i < lenght; i++) {
|
|
if (arr[i] % 2 != 0) {
|
|
arr[i] *= 10;
|
|
}
|
|
}
|
|
}
|
|
|
|
int countGreaterThen(int greater) {
|
|
int k = 0;
|
|
for (int i = 0; i < lenght; i++) {
|
|
if (arr[i] > greater) {
|
|
k++;
|
|
}
|
|
}
|
|
return k;
|
|
}
|
|
|
|
void timesLastEven(int times) {
|
|
for (int i = lenght-1; i >= 0; i--) {
|
|
if (arr[i] % 2 == 0) {
|
|
arr[i] *= times;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
int countEvenLeftOfMin() {
|
|
Element min = getMin();
|
|
|
|
int k = 0;
|
|
for (int i = 0; i < min.index; i++) {
|
|
if (arr[i] % 2 == 0) {
|
|
k++;
|
|
}
|
|
}
|
|
return k;
|
|
}
|
|
|
|
void timesOddRightOfMin(int times) {
|
|
Element min = getMin();
|
|
for (int i = min.index + 1; i < lenght; i++) {
|
|
if (arr[i] % 2 != 0) {
|
|
arr[i] *= times;
|
|
}
|
|
}
|
|
}
|
|
|
|
void ReplaceMinMax() {
|
|
Element minGet = getMin();
|
|
Element maxGet = getMax();
|
|
arr[minGet.index] = maxGet.value;
|
|
arr[maxGet.index] = minGet.value;
|
|
}
|
|
|
|
void allEven(int times) {
|
|
for (int i = 0; i < lenght; i++) {
|
|
if (arr[i] % 2 == 0) arr[i] *= times;
|
|
}
|
|
}
|
|
|
|
void allLess4() {
|
|
for (int i = 0; i < lenght; i++) {
|
|
if (arr[i] < 4) arr[i] = 4;
|
|
}
|
|
}
|
|
|
|
void right0() {
|
|
Element max = getMax();
|
|
for (int i = max.index + 1; i < lenght; i++) {
|
|
arr[i] = 0;
|
|
}
|
|
}
|
|
|
|
Element getMin() {
|
|
int min = arr[0];
|
|
int index = 0;
|
|
for (int i = 1; i < lenght; i++) {
|
|
if (arr[i] < min) {
|
|
min = arr[i];
|
|
index = i;
|
|
}
|
|
}
|
|
|
|
Element answer = { min, index };
|
|
|
|
return answer;
|
|
}
|
|
|
|
Element getMax() {
|
|
int max = arr[0];
|
|
int index = 0;
|
|
for (int i = 1; i < lenght; i++) {
|
|
if (arr[i] > max) {
|
|
max = arr[i];
|
|
index = i;
|
|
}
|
|
}
|
|
|
|
Element answer = { max, index };
|
|
|
|
return answer;
|
|
}
|
|
|
|
//14
|
|
void deleteElement(int index) {
|
|
if (! (index >= 0 && index <= lenght)) {
|
|
return;
|
|
}
|
|
|
|
lenght -= 1;
|
|
|
|
for (int i = index; i < lenght; i++) {
|
|
arr[i] = arr[i+1];
|
|
}
|
|
|
|
}
|
|
|
|
void insertElement(int value, int index) {
|
|
if (! (index >= 0 && index <= lenght)) {
|
|
return;
|
|
}
|
|
|
|
for (int i = lenght; i >index; i--) {
|
|
arr[i] = arr[i-1];
|
|
}
|
|
lenght += 1;
|
|
arr[index] = value;
|
|
}
|
|
|
|
void printArr() {
|
|
printf("< ");
|
|
for (int i = 0; i < lenght; i++) {
|
|
printf("%d ", arr[i]);
|
|
}
|
|
printf(">\n");
|
|
}
|
|
|
|
void menuText() {
|
|
printf("\n\n");
|
|
if (lenght != 0) {
|
|
printf("äëèííà: %d\n", lenght);
|
|
printArr();
|
|
}
|
|
printf("--------------\n");
|
|
printf("âûáåðèòå íóæíóþ âàì îïåðàöèÿ:\n");
|
|
printf("1) Ââåñòè ñ êëàâèàòóðó\n");
|
|
printf("2) õ10 äëÿ âñåõ íå÷åòíûõ\n");
|
|
printf("3) Íàéòè ìèíèìàëüíûé ýëåìåíò\n");
|
|
printf("4) Êîëè÷åñòâî ýë > 10\n");
|
|
printf("5) õ2 äëÿ ïîñëåäíåãî ÷åòíîãî\n");
|
|
printf("6) ñêîëüêî ÷åòíûõ ëåâåå ìèíèìàëüíîãî\n");
|
|
printf("7) õ10 äëÿ íå÷åòíûõ ïðàâåå ìèíèìàëüíîãî\n");
|
|
printf("8) ïåìåíÿòü ìåñòàìè min è max\n");
|
|
printf("9) x-1\n");
|
|
printf("10) çàìåíèòü íà 4 el<4\n");
|
|
printf("11) el>>max çàìåíèòü íà 0\n");
|
|
printf("21) óäàëèòü ïî èíäåêñó\n");
|
|
printf("22) âñòàâèòü ïî èíäåêñó\n");
|
|
printf("23) óäàëèòü ìèíèìàëüíûé\n");
|
|
printf("24) ïåðåä ìèíèìàëüíûì âñòàâèòü 0\n");
|
|
printf("25) óäàëèòü ìàêñèìàëüíûé ÷åòíûé\n");
|
|
printf("\n");
|
|
printf("0) âûéòè\n");
|
|
printf("âûáðàííàÿ îïåðàöèÿ >>> ");
|
|
}
|
|
|
|
void startProg() {
|
|
int ans;
|
|
int ind, value;
|
|
do {
|
|
menuText();
|
|
scanf_s("%d", &ans);
|
|
|
|
switch (ans)
|
|
{
|
|
case 1:
|
|
setArray();
|
|
break;
|
|
case 2:
|
|
oddX10();
|
|
break;
|
|
case 3:
|
|
printf("min = %d", getMin().index);
|
|
break;
|
|
case 4:
|
|
printf("k = %d", countGreaterThen(10));
|
|
break;
|
|
case 5:
|
|
timesLastEven(2);
|
|
break;
|
|
case 6:
|
|
printf("k = %d", countEvenLeftOfMin());
|
|
break;
|
|
case 7:
|
|
timesOddRightOfMin(10);
|
|
break;
|
|
case 8:
|
|
ReplaceMinMax();
|
|
break;
|
|
case 9:
|
|
allEven(-1);
|
|
break;
|
|
case 10:
|
|
allLess4();
|
|
break;
|
|
case 11:
|
|
right0();
|
|
break;
|
|
case 21:
|
|
printf("index: ");
|
|
;
|
|
scanf_s("%d", &ind);
|
|
deleteElement(ind);
|
|
break;
|
|
case 22:
|
|
printf("index: ");
|
|
scanf_s("%d", &ind);
|
|
|
|
printf("value: ");
|
|
scanf_s("%d", &value);
|
|
insertElement(value,ind);
|
|
break;
|
|
case 23:
|
|
deleteElement(getMin().index);
|
|
break;
|
|
case 24:
|
|
insertElement(0, getMin().index);
|
|
break;
|
|
case 25:
|
|
value = arr[0];
|
|
ind = 0;
|
|
for (int i = 1; i < lenght; i++) {
|
|
if (arr[i] % 2 == 0 && arr[i] > value) {
|
|
value = arr[i];
|
|
ind = i;
|
|
}
|
|
|
|
}
|
|
deleteElement(ind);
|
|
break;
|
|
case 0:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
} while (ans != 0);
|
|
} |