Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/29sep25/braces.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

int checkStr(char* string)
{
int balance = 0;
int len = strlen(string);
for (int i = 0; i < len; i++) {
if (string[i] == '(')
balance += 1;
else if (string[i] == ')')
balance -= 1;
if (balance < 0)
return 0;
};
if (balance == 0)
return true;
else
return false;
}

int main(void)
{
char* string = NULL;
int capacity = 10;
int size = 0;
int c;

string = malloc(capacity);

printf("Введите строку: ");

while ((c = getchar()) != '\n') {
if (size >= capacity - 1) {
capacity *= 2;
char* temp = realloc(string, capacity);
string = temp;
}
string[size++] = c;
}
string[size] = '\0';

bool correct = checkStr(string);
printf("%s\n", correct ? "true" : "false");

return 0;
}
38 changes: 38 additions & 0 deletions src/29sep25/count.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <string.h>
#include <stdio.h>

int count(char *str, char *str1)
{
int size = strlen(str);
int size1 = strlen(str1);
int number_of_substrings = 0;

if (size == 0 || size1 == 0)
return 0;

for (int start = 0; start <= size - size1; start++) {
/* если элемент совпал, продожаем считать, иначе ищем следующий стартовы элемент */
int coincidences = 0;
for (int current = 0; current < size1; current++) {
if (str1[current] == str[start + current])
coincidences += 1;
else
break;
}

/* если все элементы подстроки есть, то добавляем одно вхождение */
if (coincidences == size1)
number_of_substrings += 1;
}

return number_of_substrings;
}

int main()
{
char string[7] = "abcabc";
char string1[3] = "ab";
int result = count(string, string1);
printf("Количество вхождений %d\n", result);
return 0;
}
36 changes: 36 additions & 0 deletions src/29sep25/zero_elements.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <stdio.h>

int count_zero_elements(int arr[], int size)
{
int count = 0;

for (int i = 0; i < size; i++) {
if (arr[i] == 0)
count++;
}

return count;
}

/* в C приходится выводить массив по одному элементу */
void print_array(int arr[], int size)
{
printf("Массив: [");
for (int i = 0; i < size; i++) {
printf("%d", arr[i]);
if (i < size - 1)
printf(", ");
}
printf("]\n");
}

int main()
{
int arr[] = {1, 0, 3, 0, 5, 0, 7};
int size = sizeof(arr) / sizeof(arr[0]);
print_array(arr, size);
int zeros = count_zero_elements(arr, size);
printf("Количество нулевых элементов: %d\n", zeros);

return 0;
}