2024-11-19 15:56:22 +04:00
|
|
|
|
// fix 2
|
|
|
|
|
|
|
|
|
|
|
2024-11-19 15:55:29 +04:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <Windows.h>
|
|
|
|
|
|
|
|
|
|
#define NUM_ELEMENTS 20
|
|
|
|
|
|
|
|
|
|
int arr[NUM_ELEMENTS];
|
|
|
|
|
int arrHelp[NUM_ELEMENTS];
|
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
|
|
void printElements() {
|
|
|
|
|
printf("< ");
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
printf("%d ", arr[i]);
|
|
|
|
|
}
|
|
|
|
|
printf(">\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void keyboardInput() {
|
|
|
|
|
printf("n = ");
|
|
|
|
|
scanf_s("%d", &n);
|
|
|
|
|
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %d <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ", n);
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
scanf_s("%d", &arr[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void oddsX10() {
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
if (arr[i] % 2 == 1) {
|
|
|
|
|
arr[i] *= 10;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int findMin() {
|
|
|
|
|
int min = arr[0];
|
|
|
|
|
for (int i = 1; i < n; i++) {
|
|
|
|
|
if (arr[i] < min) {
|
|
|
|
|
min = arr[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return min;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int findMore10() {
|
|
|
|
|
int count = 0;
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
if (arr[i] > 10) {
|
|
|
|
|
count += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int findLastEven() {
|
|
|
|
|
for (int i = n - 1; i >= 0; i--) {
|
|
|
|
|
if (arr[i] % 2 == 0) {
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int findIndexMin() {
|
|
|
|
|
int min = 0;
|
|
|
|
|
for (int i = 1; i < n; i++) {
|
|
|
|
|
if (arr[i] < arr[min]) {
|
|
|
|
|
min = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return min;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int findIndexMax() {
|
|
|
|
|
int max = 0;
|
|
|
|
|
for (int i = 1; i < n; i++) {
|
|
|
|
|
if (arr[i] > arr[max]) {
|
|
|
|
|
max = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return max;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void findEvenDigits() {
|
|
|
|
|
int count = 0;
|
|
|
|
|
for (int i = findIndexMin(); i >= 0; i--) {
|
|
|
|
|
if (arr[i] % 2 == 0) {
|
|
|
|
|
count += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("%d <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void oddsXMinus1() {
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
arr[i] *= -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void changeDigitLess4() {
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
if (arr[i] < 4) {
|
|
|
|
|
arr[i] = 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void oddsReplace1() {
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
arrHelp[i] = arr[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < (n - 1); i++) {
|
|
|
|
|
if ((arrHelp[i - 1] % 2 == 0) && (arrHelp[i + 1] % 2 == 0)) {
|
|
|
|
|
arr[i] = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void X10BetweenMinMax() {
|
|
|
|
|
for (int i = findIndexMin() + 1; i < findIndexMax(); i++) {
|
|
|
|
|
arr[i] *= 10;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void X100BetweenFirstLastEven() {
|
|
|
|
|
int firstEvenIndex;
|
|
|
|
|
int lastEvenIndex;
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
if (arr[i] % 2 == 0) {
|
|
|
|
|
firstEvenIndex = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
if (arr[i] % 2 == 0) {
|
|
|
|
|
lastEvenIndex = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = firstEvenIndex + 1; i < lastEvenIndex; i++) {
|
|
|
|
|
arr[i] *= 100;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void deleteElement(int delIndex) {
|
|
|
|
|
if (delIndex >= 0 && delIndex < n) {
|
|
|
|
|
for (int i = delIndex; i < n; i++) {
|
|
|
|
|
arr[i] = arr[i + 1];
|
|
|
|
|
}
|
|
|
|
|
n--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void insertElement(int insIndex, int value) {
|
|
|
|
|
if (insIndex >= 0 && insIndex < n) {
|
|
|
|
|
for (int i = n; i > insIndex; i--) {
|
|
|
|
|
arr[i] = arr[i - 1];
|
|
|
|
|
}
|
|
|
|
|
arr[insIndex] = value;
|
|
|
|
|
n++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void delMin() {
|
|
|
|
|
int min = findIndexMin();
|
|
|
|
|
for (int i = min; i < n; i++) {
|
|
|
|
|
arr[i] = arr[i + 1];
|
|
|
|
|
}
|
|
|
|
|
n--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void insert0BeforeMin() {
|
|
|
|
|
int min = findIndexMin();
|
|
|
|
|
for (int i = n; i > min; i--) {
|
|
|
|
|
arr[i] = arr[i - 1];
|
|
|
|
|
}
|
|
|
|
|
arr[min] = 0;
|
|
|
|
|
n++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void delAllEven() {
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
if (arr[i] % 2 == 0) {
|
|
|
|
|
for (int j = i; j < n; j++) {
|
|
|
|
|
arr[j] = arr[j + 1];
|
|
|
|
|
}
|
|
|
|
|
n--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int indexMaxEven() {
|
|
|
|
|
int flag = 0;
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
if (arr[i] % 2 == 0) {
|
|
|
|
|
flag = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (flag == 1) {
|
|
|
|
|
int max = 0;
|
|
|
|
|
for (int i = 1; i < n; i++) {
|
|
|
|
|
if (arr[i] > arr[max] && arr[i] % 2 == 0) {
|
|
|
|
|
max = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return max;
|
|
|
|
|
}
|
|
|
|
|
printf("<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void insAfterMaxEven0() {
|
|
|
|
|
int maxEven = indexMaxEven();
|
|
|
|
|
if (arr[maxEven] % 2 == 0 && arr[maxEven] != 0) {
|
|
|
|
|
for (int i = n; i > maxEven + 1; i--) {
|
|
|
|
|
arr[i] = arr[i - 1];
|
|
|
|
|
}
|
|
|
|
|
arr[maxEven + 1] = 0;
|
|
|
|
|
n++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
SetConsoleCP(1251);
|
|
|
|
|
SetConsoleOutputCP(1251);
|
|
|
|
|
int item;
|
|
|
|
|
do {
|
|
|
|
|
printf("\n");
|
|
|
|
|
printf("------------------------------\n");
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
|
|
|
|
|
printElements();
|
|
|
|
|
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> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
printf("2: x10 <20><><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><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> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> > 10\n");
|
|
|
|
|
printf("5: 2x <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><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> -1\n");
|
|
|
|
|
printf("8: <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> < 4 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> 4\n");
|
|
|
|
|
printf("9: <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> 1\n");
|
|
|
|
|
printf("10: <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> 10 <20><><EFBFBD>\n");
|
|
|
|
|
printf("11: <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> 100 <20><><EFBFBD>\n");
|
|
|
|
|
printf("12: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
printf("13: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
printf("14: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
printf("15: <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0\n");
|
|
|
|
|
printf("16: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
printf("17: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0\n");
|
|
|
|
|
printf("\n");
|
|
|
|
|
printf("0: <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> >>>>>> ");
|
|
|
|
|
scanf_s("%d", &item);
|
|
|
|
|
|
|
|
|
|
switch(item) {
|
|
|
|
|
case 1:
|
|
|
|
|
keyboardInput();
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
oddsX10();
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
{
|
|
|
|
|
int min = findMin();
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD> = %d\n", min);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
{
|
|
|
|
|
int more10 = findMore10();
|
|
|
|
|
printf("%d <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> 10\n", more10);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
{
|
|
|
|
|
int index = findLastEven();
|
|
|
|
|
if (index >= 0) {
|
|
|
|
|
arr[index] *= 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
findEvenDigits();
|
|
|
|
|
break;
|
|
|
|
|
case 7:
|
|
|
|
|
oddsXMinus1();
|
|
|
|
|
break;
|
|
|
|
|
case 8:
|
|
|
|
|
changeDigitLess4();
|
|
|
|
|
break;
|
|
|
|
|
case 9:
|
|
|
|
|
oddsReplace1();
|
|
|
|
|
break;
|
|
|
|
|
case 10:
|
|
|
|
|
X10BetweenMinMax();
|
|
|
|
|
break;
|
|
|
|
|
case 11:
|
|
|
|
|
X100BetweenFirstLastEven();
|
|
|
|
|
break;
|
|
|
|
|
case 12:
|
|
|
|
|
{
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> = ");
|
|
|
|
|
int index;
|
|
|
|
|
scanf_s("%d", &index);
|
|
|
|
|
|
|
|
|
|
deleteElement(index);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 13:
|
|
|
|
|
{
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> = ");
|
|
|
|
|
int index;
|
|
|
|
|
scanf_s("%d", &index);
|
|
|
|
|
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> = ");
|
|
|
|
|
int value;
|
|
|
|
|
scanf_s("%d", &value);
|
|
|
|
|
|
|
|
|
|
insertElement(index, value);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 14:
|
|
|
|
|
delMin();
|
|
|
|
|
break;
|
|
|
|
|
case 15:
|
|
|
|
|
insert0BeforeMin();
|
|
|
|
|
break;
|
|
|
|
|
case 16:
|
|
|
|
|
delAllEven();
|
|
|
|
|
break;
|
|
|
|
|
case 17:
|
|
|
|
|
insAfterMaxEven0();
|
|
|
|
|
break;
|
|
|
|
|
};
|
|
|
|
|
} while (item != 0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|