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("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %d <20><><EFBFBD><EFBFBD><EFBFBD>: ", 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("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: %d\n", lenght);
|
|||
|
printArr();
|
|||
|
}
|
|||
|
printf("--------------\n");
|
|||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
|
|||
|
printf("1) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("2) <20>10 <20><><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("3) <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("4) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> > 10\n");
|
|||
|
printf("5) <20>2 <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("6) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("7) <20>10 <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("8) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> min <20> max\n");
|
|||
|
printf("9) x-1\n");
|
|||
|
printf("10) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> 4 el<4\n");
|
|||
|
printf("11) el>>max <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> 0\n");
|
|||
|
printf("21) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("22) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("23) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("24) <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0\n");
|
|||
|
printf("25) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("\n");
|
|||
|
printf("0) <20><><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> >>> ");
|
|||
|
}
|
|||
|
|
|||
|
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);
|
|||
|
}
|