Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sergeev Nikita #19

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <locale.h>

int main() {
setlocale(LC_ALL, "rus");

srand(time(0));
int random_number = rand() % 9000 + 1000;
int ch = 0;

int r4 = random_number % 10;
int r3 = ((random_number % 100) - r4) / 10;
int r2 = ((random_number % 1000) - r3) / 100;
int r1 = (random_number - r2) / 1000;
printf("%d\n", random_number);

while (ch != random_number) {

printf("������� �������������� �����\n");
scanf_s("%d", &ch);
if (ch < 1000 || ch > 9999) {
printf("������! ������� �������������� �����.\n");
continue;
}

int k = 0;

int m4 = ch % 10;
int m3 = ((ch % 100) - m4) / 10;
int m2 = ((ch % 1000) - m3) / 100;
int m1 = (ch - m2) / 1000;

if (r1 == m1) k++;
if (r2 == m2) k++;
if (r3 == m3) k++;
if (r4 == m4) k++;

int b = 0;

int r_digits[4] = {r1, r2, r3, r4};
int m_digits[4] = {m1, m2, m3, m4};

int r_used[4] = {0};
int m_used[4] = {0};

for (int i = 0; i < 4; i++) {
if (r_digits[i] == m_digits[i]) {
r_used[i] = 1;
m_used[i] = 1;
}
}


for (int i = 0; i < 4; i++) {
if (m_used[i] != 1) {
for (int j = 0; j < 4; j++) {
if (r_used[j] != 1 && m_digits[i] == r_digits[j]) {
b++;
r_used[j] = 1;
m_used[i] = 1;
break;
}
}
}
}


if (k == 0) printf("0 �����\n");
else if (k == 1) printf("1 ������\n");
else if (k > 1) printf("%d ������\n", k);

if (b == 0) printf("0 �����\n");
else if (b == 1) printf("1 ���\n");
else if (b > 1) printf("%d ����\n", b);

if (ch == random_number) {
printf("�� ������� �����: %d\n", random_number);
break;
}
}



return 0;
}
74 changes: 74 additions & 0 deletions 22_Sergeev_Nikita/двумерные массивы/14 2D.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <locale.h>


int min(int a, int b) {
return (a < b) ? a : b;
}

int main() {
setlocale(LC_ALL, "rus");
srand(time(NULL));

int rows = rand() % 5 + 1;
int cols = rand() % 5 + 1;

printf("������� �������: %d x %d\n", rows, cols);


int** A = (int**)malloc(rows * sizeof(int*));
for (int i = 0; i < rows; i++) {
A[i] = (int*)malloc(cols * sizeof(int));
}


printf("\n�������� ������ A:\n");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
A[i][j] = rand() % 100 + 1;
printf("%4d ", A[i][j]);
}
printf("\n");
}


int k = 101;
int stolbec = 0;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
if (A[i][j] < k) {
k = A[i][j];
stolbec = j;
}
}
}

printf("\n����������� �������: %d � ������� %d\n", k, stolbec);


int** B = (int**)malloc(rows * sizeof(int*));
for (int i = 0; i < rows; i++) {
B[i] = (int*)malloc((cols - 1) * sizeof(int));
}

for (int i = 0; i < rows; i++) {
int b_col = 0;
for (int j = 0; j < cols; j++) {
if (j == stolbec) continue;
B[i][b_col] = A[i][j];
b_col++;
}
}

printf("\n������ B\n");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols - 1; j++) {
printf("%4d ", B[i][j]);
}
printf("\n");
}

return 0;
}
59 changes: 59 additions & 0 deletions 22_Sergeev_Nikita/двумерные массивы/20 2D.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>

int main() {
setlocale(LC_ALL, "rus");

int employees, months;

printf("������� ���������� �����������: ");
scanf_s("%d", &employees);
printf("������� ���������� �������: ");
scanf_s("%d", &months);


double* hourly_rates = (double*)malloc(employees * sizeof(double));
int** hours_worked = (int**)malloc(employees * sizeof(int*));
double** salaries = (double**)malloc(employees * sizeof(double*));

for (int i = 0; i < employees; i++) {
hours_worked[i] = (int*)malloc(months * sizeof(int));
salaries[i] = (double*)malloc(months * sizeof(double));
}


for (int i = 0; i < employees; i++) {
printf("\n������� ��������� ������ ���������� %d: ", i + 1);
scanf_s("%lf", &hourly_rates[i]);

printf("������� ���������� ������������ ����� ��� ���������� %d �� ������ �����:\n", i + 1);
for (int j = 0; j < months; j++) {
printf("����� %d: ", j + 1);
scanf_s("%d", &hours_worked[i][j]);
}
}


printf("\n�������� ����������� �� ������ �����:\n");
for (int i = 0; i < employees; i++) {
printf("\n��������� %d:\n", i + 1);
for (int j = 0; j < months; j++) {
salaries[i][j] = hourly_rates[i] * hours_worked[i][j];
printf("����� %d: %.2f\n", j + 1, salaries[i][j]);
}
}

printf("\n����� ���� �������� �� ������ �����:\n");
for (int j = 0; j < months; j++) {
double total_fund = 0.0;
for (int i = 0; i < employees; i++) {
total_fund += salaries[i][j];
}
printf("����� %d: %.2f\n", j + 1, total_fund);
}



return 0;
}
48 changes: 48 additions & 0 deletions 22_Sergeev_Nikita/кр/1 задание кр.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <stdio.h>
#include <stdlib.h>

int main() {
int A[11] = { 1, 6, 6, 3, 7, 9, 5, 10, 11, 111, 1111};
int B[8] = { 3, 5, 6, 6, 7, 9, 11};
int a_size = sizeof(A) / sizeof(A[0]);
int b_size = sizeof(B) / sizeof(B[0]);
int* C = (int*)malloc(sizeof(B));
int count = 0;

for (int i = 0; i < a_size; i++) {
for (int j = 0; j < b_size; j++) {
if (A[i] == B[j]) {
C[count] = A[i];
count++;
}
}

}

int uni = 0;
int* uniq = (int*)malloc(sizeof(C));

for (int i = 0; i < count; i++) {
int dubl = 0;
for (int j = 0; j < uni; j++) {
if (C[i] == uniq[j]) {
dubl = 1;
break;
}
}
if (dubl == 0) {
uniq[uni] = C[i];
uni++;
}
}

for (int i = 0; i < uni; i++) {
printf("%d ", uniq[i]);

}




return 0;
}
81 changes: 81 additions & 0 deletions 22_Sergeev_Nikita/кр/двумерные массивы.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <time.h>


int max(int a, int b) {
return (a > b) ? a : b;
}

int main() {
setlocale(LC_ALL, "rus");
srand(time(NULL));


int rows = rand() % 4 + 2;
int cols = rand() % 4 + 2;

printf("������ �������: %d x %d\n", rows, cols);


int** A = (int**)malloc(rows * sizeof(int*));
for (int i = 0; i < rows; i++) {
A[i] = (int*)malloc(cols * sizeof(int));
}


printf("��������� ������:\n");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
A[i][j] = rand() % 100 + 1;
printf("%4d", A[i][j]);
}
printf("\n");
}


int sum = 0;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
sum += A[i][j];
}
}


float mid = (float)sum / (rows * cols);
printf("\n������� ��������: %.3f\n", mid);


int* count = (int*)calloc(cols, sizeof(int));

for (int j = 0; j < cols; j++) {
int k = 0;
for (int i = 0; i < rows; i++) {
if (A[i][j] > mid) k++;
}
count[j] = k;
}


int max_count = 0;
int stolbec = 0;

for (int j = 0; j < cols; j++) {
if (count[j] > max_count) {
max_count = count[j];
stolbec = j;
}
}

printf("\n������� %d (%d �����(�))\n", stolbec, max_count);


for (int i = 0; i < rows; i++) {
free(A[i]);
}
free(A);
free(count);

return 0;
}
Loading