343 lines
5.8 KiB
C
343 lines
5.8 KiB
C
// fix 2
|
|
|
|
|
|
#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("ââåäèòå %d çíà÷åíèÿ: ", 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 ëåâåå ìèíèìàëüíîãî", 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(" ìàññèâå íåò ÷åòíûõ ÷èñåë");
|
|
}
|
|
|
|
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("Ñîäåðæèìîå ìàññèâà:");
|
|
printElements();
|
|
printf("Âûáåðèòå íóæíóþ âàì îïåðàöèþ:\n");
|
|
printf("1: Ââåñòè ñ êëàâèàòóðû ìàññèâ\n");
|
|
printf("2: x10 äëÿ âñåõ íå÷åòíûõ ýëåìåíòîâ\n");
|
|
printf("3: Íàéòè ìèíèìàëüíûé ýëåìåíò\n");
|
|
printf("4: Ñêîëüêî ýëåìåíòîâ > 10\n");
|
|
printf("5: 2x äëÿ ïîñëåäíåãî ÷åòíîãî\n");
|
|
printf("6: Ñêîëüêî ÷¸òíûõ ëåâåå ìèíèìàëüíîãî\n");
|
|
printf("7: Âñå ÷åòíûå ýëåìåíòû óìíîæèòü íà -1\n");
|
|
printf("8: Âñå ýëåìåíòû < 4 çàìåíèòü íà 4\n");
|
|
printf("9: Âñå íå÷åòíûå ýëåìåíòû çàìåíèòü íà 1\n");
|
|
printf("10: Âñå ýëåìåíòû ìåæäó ìàêñèìàëüíûì è ìèíèìàëüíûì óâåëè÷èòü â 10 ðàç\n");
|
|
printf("11: Âñå ýëåìåíòû ìåæäó ïåðâûì è ïîñëåäíèì ÷åòíûì óâåëè÷èòü â 100 ðàç\n");
|
|
printf("12: Óäàëèòü ýëåìåíò\n");
|
|
printf("13: Âñòàâèòü ýëåìåíò\n");
|
|
printf("14: Óäàëèòü ìèíèìàëüíûé ýëåìåíò\n");
|
|
printf("15: Ïåðåä ìèíèìàëüíûì ýëåìåíòîì âñòàâèòü 0\n");
|
|
printf("16: Óäàëèòü âñå ÷åòíûå ýëåìåíòû\n");
|
|
printf("17: Âñòàâèòü ïîñëå ìàêñèìàëüíîãî èç ÷åòíûõ ýëåìåíòîâ 0\n");
|
|
printf("\n");
|
|
printf("0: Âûéòè èç ïðîãðàììû\n");
|
|
printf("Âûáðàííàÿ îïåðàöèÿ >>>>>> ");
|
|
scanf_s("%d", &item);
|
|
|
|
switch(item) {
|
|
case 1:
|
|
keyboardInput();
|
|
break;
|
|
case 2:
|
|
oddsX10();
|
|
break;
|
|
case 3:
|
|
{
|
|
int min = findMin();
|
|
printf("ìèí = %d\n", min);
|
|
}
|
|
break;
|
|
case 4:
|
|
{
|
|
int more10 = findMore10();
|
|
printf("%d ýëåìåíòîâ áîëüøå ÷åì 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("Èíäåêñ óäàëÿåìîãî ýëåìåíòà = ");
|
|
int index;
|
|
scanf_s("%d", &index);
|
|
|
|
deleteElement(index);
|
|
}
|
|
break;
|
|
case 13:
|
|
{
|
|
printf("Èíäåêñ âñòàâëÿåìîãî ýëåìåíòà = ");
|
|
int index;
|
|
scanf_s("%d", &index);
|
|
|
|
printf("Çíà÷åíèå âñòàâëÿåìîãî ýëåìåíòà = ");
|
|
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;
|
|
} |