минорные изменения

This commit is contained in:
Kaehvaman 2025-01-21 21:05:16 +04:00
parent 1b2ab06b3a
commit 8c2a9f885e
6 changed files with 934 additions and 872 deletions

View File

@ -44,6 +44,7 @@
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<EnableASAN>true</EnableASAN>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
@ -51,6 +52,7 @@
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<EnableASAN>false</EnableASAN>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">

View File

@ -2,6 +2,10 @@
#include <stdio.h>
#include <Windows.h>
/*
* íå çàáóäü âêëþ÷èòü AddressSanitizer / ñàíèòàéçåð àäðåñîâ
*/
int N1;
int N2;
int M2;
@ -202,6 +206,51 @@ void task3() {
printf("> Âûïîëíåíî çàäàíèå 3\n");
}
int countRow(int* buf, int len, int target)
{
int count = 0;
for (int i = 0; i < len; i++) {
if (buf[i] == target) {
count += 1;
}
}
return 0;
}
int countColumn(int num, int column)
{
int count = 0;
for (int n = 0; n < N2; n++) {
if (A2[n][column] == num) {
count += 1;
}
}
return count;
}
// Óäàëèòü òå ñòîëáöû â êîòîðûõ âñòðå÷àåòñÿ õîòÿ áû äâà îäèíàêîâûõ ýëåìåíòà
void taskAnton()
{
for (int m = 0; m < M2; m++) {
for (int n = 0; n < N2; n++) {
if (countColumn(A2[n][m], m) > 1) {
deleteColumn(m);
m -= 1;
break;
}
}
}
printf("> Âûïîëíåíî çàäàíèå Àíòîíà\n");
}
void print1D(int* buf, int len)
{
for (int i = 0; i < len; i++) {
printf("%d ", buf[i]);
}
printf("\n");
}
int main()
{
SetConsoleCP(1251);
@ -209,13 +258,19 @@ int main()
loadLists("test1.txt");
printLists();
task2();
task3();
//task2();
//task3();
taskAnton();
printLists();
//print1D(A2[1], M2);
saveLists("out.txt");
while (1) {
}
return 0;
}

View File

@ -1,5 +1,10 @@
6
1 2 104 106 7 8
2 4
6 4 5 1
2 3 4 3
1 2 4 6 7 8
7 2
-2 1
3 6
6 10
10 -11
9 3
2 -1
5 -8

View File

@ -1,10 +1,10 @@
6
1 2 4 6 7 8
7 4
-2 -1 0 1
3 4 -5 6
6 4 5 1
10 -1 0 1
2 3 4 3
-2 1 0 1
3 8 -5 6
6 -4 5 10
10 -1 0 -11
9 3 4 3
2 1 0 -1
5 -6 7 -8

View File

@ -1,218 +1,218 @@
#include <stdio.h>
#include <Windows.h>
int index(int num, int arr[], int len) {
for (int i = 0; i < len; i++) {
if (arr[i] == num) return i;
}
return -1;
}
int count(int num, int arr[], int len) {
int count = 0;
for (int i = 0; i < len; i++) {
if (arr[i] == num) count += 1;
}
return count;
}
int arrmax(int arr[], int len) {
int max = arr[0];
for (int i = 1; i < len; i++) {
if (arr[i] > max) max = arr[i];
}
return max;
}
int arrmin(int arr[], int len) {
int min = arr[0];
for (int i = 1; i < len; i++) {
if (arr[i] < min) min = arr[i];
}
return min;
}
void printarr(int arr[], int len) {
printf("[");
for (int i = 0; i < len; i++) {
printf("%d, ", arr[i]);
}
printf("\b\b]\n");
}
void deleteindex(int index, int arr[], int* len) {
arr[index] = 0;
for (int i = index; i < *len - 1; i++) {
arr[i] = arr[i + 1];
}
*len -= 1;
}
void insert(int num, int index, int arr[], int* len) {
for (int i = *len; i > index; i--) {
arr[i] = arr[i - 1];
}
*len += 1;
arr[index] = num;
}
void deletemax3(int arr[], int* len) {
int max = arr[0];
int maxi = 0;
for (int i = 1; i < *len; i++) {
if (arr[i] > max && arr[i] % 3 == 0) {
max = arr[i];
maxi = i;
}
}
deleteindex(maxi, arr, len);
}
exchange_max_chains(int A[], int B[], int* sA, int* sB) {
int a = A[0], sa = 1, ai = 0;
int b = B[0], sb = 1, bi = 0;
int ts = 1;
for (int i = 0; i < *sA - 1; i++) {
if (A[i] == A[i + 1]) {
ts += 1;
}
else if (ts > sa) {
sa = ts;
ai = i + 1 - sa;
ts = 1;
a = A[i];
}
}
ts = 1;
for (int i = 0; i < *sB - 1; i++) {
if (B[i] == B[i + 1]) {
ts += 1;
}
else if (ts > sb) {
sb = ts;
bi = i + 1 - sb;
ts = 1;
b = B[i];
}
}
for (int i = 0; i < sa; i++) {
deleteindex(ai, A, sA);
}
for (int i = 0; i < sb; i++) {
insert(b, ai, A, sA);
}
for (int i = 0; i < sb; i++) {
deleteindex(bi, B, sB);
}
for (int i = 0; i < sa; i++) {
insert(a, bi, B, sB);
}
printf("A: %d %d %d\n", a, sa, ai);
printf("B: %d %d %d\n", b, sb, bi);
printf("A = ");
printarr(A, *sA);
printf("B = ");
printarr(B, *sB);
}
//#define ARRLEN 10
int main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int arr[20] = { 3, 7, 12, 3, 4, 8, -1, 6, 1, 7 };
int size = 10;
int A[20] = {3, 2, 2, 5, 2, 1, 1, 1, 3, 9};
int sA = 10;
int B[20] = {1, 2, 5, 5, 4, 8, 3, 3};
int sB = 8;
int id, val;
int n = 0;
do {
puts("\n");
printf("Ñîäåðæèìîå ìàññèâà : ");
printarr(arr, size);
puts("Âûáåðèòå ïðîãðàììó");
puts("1) Óäàëèòü ýëåìåíò ïî èíäåêñó");
puts("2) Âñòàâèòü ýëåìåíò ïî èíäåêñó");
puts("3) Óäàëèòü ìèíèìàëüíûé ýëåìåíò");
puts("4) Ïåðåä ìèíèìàëüíûì ýëåìåíòîì âñòàâèòü 0");
puts("5) Óäàëèòü âñå ÷¸òíûå ýëåìåíòû");
puts("6) Äóáëèðîâàòü âñå ÷¸òíûå ýëåìåíòû");
puts("7) Äîáàâèòü â íà÷àëî ýëåìåíò, ðàâíûé ìèíèìàëüíîìó");
puts("99) Óäàëèòü ìàêñèìàëüíûé ýëåìåíò êðàòíûé òð¸ì");
puts("10) Óäàëèòü ýëåìåíòû, âñòðå÷àþùèåñÿ â ìàññèâå òîëüêî îäèí ðàç");
puts("11) Ìåæäó ìàññèâàìè A è B îáìåíÿòü èõ ñàìûå äëèííûå öåïî÷êè èç îäèíàêîâûõ ýëåìåíòîâ");
puts("");
puts("0) exit program");
while (scanf_s(" %d", &n) != 1) {
scanf_s("%*[^\n]");
scanf_s("%*c");
}
puts("");
switch (n)
{
case 1:
printf("delete index = ");
scanf_s("%d", &id);
deleteindex(id, arr, &size);
break;
case 2:
printf("value = ");
scanf_s("%d", &val);
printf("index = ");
scanf_s("%d", &id);
insert(val, id, arr, &size);
break;
case 3:
deleteindex(index(arrmin(arr, size), arr, size), arr, &size);
break;
case 4:
insert(0, index(arrmin(arr, size), arr, size), arr, &size);
break;
case 5:
for (int i = 0; i < size; i++) {
if (arr[i] % 2 == 0) deleteindex(i, arr, &size);
}
break;
case 6:
for (int i = 0; i < size; i++) {
if (arr[i] % 2 == 0) {
insert(arr[i], i, arr, &size);
i += 2;
}
}
break;
case 7:
insert(arrmin(arr, size), 0, arr, &size);
break;
case 99:
deletemax3(arr, &size);
break;
case 10:
for (int i = 0; i < size; i++) {
if (count(arr[i], arr, size) == 1) {
deleteindex(index(arr[i], arr, size), arr, &size);
i -= 1;
}
}
break;
case 11:
exchange_max_chains(A, B, &sA, &sB);
break;
case 0:
puts("goodbye :3");
break;
default:
puts("error: wrong N");
break;
}
} while (n != 0);
return 0;
}
#include <stdio.h>
#include <Windows.h>
int index(int num, int arr[], int len) {
for (int i = 0; i < len; i++) {
if (arr[i] == num) return i;
}
return -1;
}
int count(int num, int arr[], int len) {
int count = 0;
for (int i = 0; i < len; i++) {
if (arr[i] == num) count += 1;
}
return count;
}
int arrmax(int arr[], int len) {
int max = arr[0];
for (int i = 1; i < len; i++) {
if (arr[i] > max) max = arr[i];
}
return max;
}
int arrmin(int arr[], int len) {
int min = arr[0];
for (int i = 1; i < len; i++) {
if (arr[i] < min) min = arr[i];
}
return min;
}
void printarr(int arr[], int len) {
printf("[");
for (int i = 0; i < len; i++) {
printf("%d, ", arr[i]);
}
printf("\b\b]\n");
}
void deleteindex(int index, int arr[], int* len) {
arr[index] = 0;
for (int i = index; i < *len - 1; i++) {
arr[i] = arr[i + 1];
}
*len -= 1;
}
void insert(int num, int index, int arr[], int* len) {
for (int i = *len; i > index; i--) {
arr[i] = arr[i - 1];
}
*len += 1;
arr[index] = num;
}
exchange_max_chains(int A[], int B[], int* sA, int* sB) {
int a = A[0], sa = 1, ai = 0;
int b = B[0], sb = 1, bi = 0;
int ts = 1;
for (int i = 0; i < *sA - 1; i++) {
if (A[i] == A[i + 1]) {
ts += 1;
}
else if (ts > sa) {
sa = ts;
ai = i + 1 - sa;
ts = 1;
a = A[i];
}
}
ts = 1;
for (int i = 0; i < *sB - 1; i++) {
if (B[i] == B[i + 1]) {
ts += 1;
}
else if (ts > sb) {
sb = ts;
bi = i + 1 - sb;
ts = 1;
b = B[i];
}
}
for (int i = 0; i < sa; i++) {
deleteindex(ai, A, sA);
}
for (int i = 0; i < sb; i++) {
insert(b, ai, A, sA);
}
for (int i = 0; i < sb; i++) {
deleteindex(bi, B, sB);
}
for (int i = 0; i < sa; i++) {
insert(a, bi, B, sB);
}
printf("A: %d %d %d\n", a, sa, ai);
printf("B: %d %d %d\n", b, sb, bi);
printf("A = ");
printarr(A, *sA);
printf("B = ");
printarr(B, *sB);
}
void deletemax3(int arr[], int* len) {
int max = arr[0];
int maxi = 0;
for (int i = 1; i < *len; i++) {
if (arr[i] > max && arr[i] % 3 == 0) {
max = arr[i];
maxi = i;
}
}
deleteindex(maxi, arr, len);
}
//#define ARRLEN 10
int main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int arr[20] = { 3, 7, 12, 3, 4, 8, -1, 6, 1, 7 };
int size = 10;
int A[20] = {3, 2, 2, 5, 2, 1, 1, 1, 3, 9};
int sA = 10;
int B[20] = {1, 2, 5, 5, 4, 8, 3, 3};
int sB = 8;
int id, val;
int n = 0;
do {
puts("\n");
printf("Ñîäåðæèìîå ìàññèâà : ");
printarr(arr, size);
puts("Âûáåðèòå ïðîãðàììó");
puts("1) Óäàëèòü ýëåìåíò ïî èíäåêñó");
puts("2) Âñòàâèòü ýëåìåíò ïî èíäåêñó");
puts("3) Óäàëèòü ìèíèìàëüíûé ýëåìåíò");
puts("4) Ïåðåä ìèíèìàëüíûì ýëåìåíòîì âñòàâèòü 0");
puts("5) Óäàëèòü âñå ÷¸òíûå ýëåìåíòû");
puts("6) Äóáëèðîâàòü âñå ÷¸òíûå ýëåìåíòû");
puts("7) Äîáàâèòü â íà÷àëî ýëåìåíò, ðàâíûé ìèíèìàëüíîìó");
puts("99) Óäàëèòü ìàêñèìàëüíûé ýëåìåíò êðàòíûé òð¸ì");
puts("10) Óäàëèòü ýëåìåíòû, âñòðå÷àþùèåñÿ â ìàññèâå òîëüêî îäèí ðàç");
puts("11) Ìåæäó ìàññèâàìè A è B îáìåíÿòü èõ ñàìûå äëèííûå öåïî÷êè èç îäèíàêîâûõ ýëåìåíòîâ");
puts("");
puts("0) exit program");
while (scanf_s(" %d", &n) != 1) {
scanf_s("%*[^\n]");
scanf_s("%*c");
}
puts("");
switch (n)
{
case 1:
printf("delete index = ");
scanf_s("%d", &id);
deleteindex(id, arr, &size);
break;
case 2:
printf("value = ");
scanf_s("%d", &val);
printf("index = ");
scanf_s("%d", &id);
insert(val, id, arr, &size);
break;
case 3:
deleteindex(index(arrmin(arr, size), arr, size), arr, &size);
break;
case 4:
insert(0, index(arrmin(arr, size), arr, size), arr, &size);
break;
case 5:
for (int i = 0; i < size; i++) {
if (arr[i] % 2 == 0) deleteindex(i, arr, &size);
}
break;
case 6:
for (int i = 0; i < size; i++) {
if (arr[i] % 2 == 0) {
insert(arr[i], i, arr, &size);
i += 2;
}
}
break;
case 7:
insert(arrmin(arr, size), 0, arr, &size);
break;
case 99:
deletemax3(arr, &size);
break;
case 10:
for (int i = 0; i < size; i++) {
if (count(arr[i], arr, size) == 1) {
deleteindex(index(arr[i], arr, size), arr, &size);
i -= 1;
}
}
break;
case 11:
exchange_max_chains(A, B, &sA, &sB);
break;
case 0:
puts("goodbye :3");
break;
default:
puts("error: wrong N");
break;
}
} while (n != 0);
return 0;
}

File diff suppressed because it is too large Load Diff