This commit is contained in:
bel.riose 2024-11-21 09:47:00 +04:00
commit fbdb3d8b94

189
Lab
View File

@ -1,37 +1,176 @@
#include <stdio.h> #include <stdio.h>
#include <Windows.h> #include <Windows.h>
int strlen_my(char *s) #define NUM_ELEMENTS 100
{
int i = 0; int arr[NUM_ELEMENTS];
char* p = s; int n = 0;
while (*p++) { void addLastElement(int a) {
i++; arr[n++] = a;
} }
return i; void printElements() {
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
} }
int strcpy_my(char* dest, char* src) printf("\n");
{
int i = 0;
while (src[i] != "\0") {
dest[i] = src[i];
i++;
} }
printf("\nBû ïîëó÷àåòå ñòðîêó s = \"%s\"", dest);
int findMin() {
int min = arr[0];
for (int i = 1; i < n; i++) {
if (arr[i] < min) {
min = arr[i];
} }
}
return min;
}
int findMin2() {
int min = arr[0];
int o;
for (int i = 1; i < n; i++) {
if (arr[i] < min) {
min = arr[i];
o = i;
}
}
return o;
}
int findMax() {
int max = 0;
int o;
for (int i = 1; i < n; i++) {
if (arr[i] > max && arr[i]%2==0) {
max = arr[i];
o = i;
}
}
return o;
}
void keyboardInput() {
printf("n = ");
scanf_s("%d", &n);
printf("input %d values: ", n);
for (int i = 0; i < n; i++) {
scanf_s("%d", &arr[i]);
}
}
void deleteElement(int a){
int k = n;
printf("%d", k);
for (; a < n-1; a++) {
arr[a] = arr[a + 1];
}
n = n - 1;
}
void insertElement(int a,int b){
addLastElement(arr[n-1]);
int k = n;
int l = b;
printf("%d", k);
for (; a < k; k--) {
arr[k-1] = arr[k-2];
}
arr[a] = l;
}
void minEl0() {
int m = findMin();
int r;
int k = n;
for (int i = 0; i < n; i++) {
if (arr[i] == m) {
r = i;
}
}
addLastElement(arr[n - 1]);
printf("%d", k);
while (k > 0) {
arr[k] = arr[k - 1];
k--;
}
arr[r] = 0;
}
void priz() {
int m = findMax();
addLastElement(arr[n - 1]);
int r;
int k = n;
for (; m+2 < k; k--) {
arr[k] = arr[k - 1];
k--;
}
arr[m + 1] = 0;
}
void main() { void main() {
/*char s[10] = "Hi!"; SetConsoleCP(1251);
printf("len = %d\n", strlen_my(s)); SetConsoleOutputCP(1251);
int item;
do {
printf("\n");
printf("------------------------------\n");
printf("Ńîäĺđćčěîĺ ěŕńńčâŕ:");
printElements();
printf("Âűáĺđčňĺ íóćíóţ âŕě îďĺđŕöčţ:\n");
printf("1: Ââĺńňč ń ęëŕâčŕňóđű ěŕńńčâ\n");
printf("2: Óäŕëčňü âűáđŕííűé ýëĺěĺíň\n");
printf("3: Ââĺńňč ýëĺěĺíň íŕ âűáđŕííîĺ ěĺńňî\n");
printf("4: Óäŕëčňü ěčíčěŕëüíűé ýëĺěĺíň\n");
printf("5: Ďĺđĺä ěčíčěŕëüíűě ýëĺěĺíňîě âńňŕâčňü 0\n");
printf("6: Ďîńëĺ ěŕęńčěŕëüíîăî ÷¸ňíîăî ýëĺěĺíňŕ âńňŕâčňü 0\n");
s[3] = ' '; s[4] = '\0';
printf("len = %d\n", strlen_my(s));
s[4] = 'W'; s[5] = 'o'; s[6] = 'r'; s[7] = 'l'; printf("\n");
s[8] = 'd'; s[9] = '\0'; printf("0: Âűéňč čç ďđîăđŕěěű \n");
printf("len = %d\n", strlen_my(s)); printf("Âűáđŕííŕ˙ îďĺđŕöč˙ >>>>>> ");
*/
char dest[10] = "YYYYY"; scanf_s("%d", &item);
char src[10] = "GGGGG"; switch (item) {
strcpy_my(dest, src); case 1:
keyboardInput();
break;
case 2:
printf("Ââĺäčňĺ číäĺęń óäîë˙ĺěîăî ýëĺěĺíňŕ ");
int a;
scanf_s("%d", &a);
deleteElement(a);
break;
case 3:
{
printf("Ďđĺä ęŕęčě ýëĺěĺíňîě âńňŕâčňü íîâűé? Číäĺęń = ");
int a;
scanf_s("%d", &a);
printf("Ęŕęîĺ çíŕ÷ĺíčĺ âńňŕâčňü = ");
int b;
scanf_s("%d", &b);
insertElement(a,b);
break;
break;
}
case 4:
{
deleteElement(findMin2());
break;
}
case 5:
{
minEl0();
break;
}
case 6:
{
priz();
break;
}
}
} while (item != 0);
} }