Skip to content
This repository was archived by the owner on Jun 29, 2026. It is now read-only.
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
134 changes: 127 additions & 7 deletions src/fun.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,134 @@
// Copyright 2022 UNN-IASR
#include "fun.h"

unsigned int faStr1(const char *str) {
return 0;
bool isSpace(char c)
{
return c == ' ';
}

unsigned int faStr2(const char *str) {
return 0;
bool isDigit(char c)
{
return c >= '0' && c <= '9';
}

unsigned int faStr3(const char *str) {
return 0;
bool isUpperLatin(char c)
{
return c >= 'A' && c <= 'Z';
}

bool isLowerLatin(char c)
{
return c >= 'a' && c <= 'z';
}

// Задача 1

unsigned int faStr1(const char *str)
{
if (str == nullptr)
return 0;

unsigned int count = 0;
int i = 0;

while (str[i] != '\0')
{
while (str[i] != '\0' && isSpace(str[i]))
i++;

if (str[i] == '\0')
break;

bool hasDigit = false;

while (str[i] != '\0' && !isSpace(str[i]))
{
if (isDigit(str[i]))
hasDigit = true;
i++;
}

if (!hasDigit)
count++;
}

return count;
}

// Задача 2
unsigned int faStr2(const char *str)
{
if (str == nullptr)
return 0;

unsigned int count = 0;
int i = 0;

while (str[i] != '\0')
{
while (str[i] != '\0' && isSpace(str[i]))
i++;

if (str[i] == '\0')
break;

bool valid = true;
int wordLength = 0;

if (!isUpperLatin(str[i]))
valid = false;

wordLength++;
i++;

while (str[i] != '\0' && !isSpace(str[i]))
{
if (!isLowerLatin(str[i]))
valid = false;

wordLength++;
i++;
}

if (valid && wordLength > 0)
count++;
}

return count;
}

// Задача 3

unsigned int faStr3(const char *str)
{
if (str == nullptr)
return 0;

unsigned int wordCount = 0;
unsigned int totalLength = 0;
int i = 0;

while (str[i] != '\0')
{
while (str[i] != '\0' && isSpace(str[i]))
i++;

if (str[i] == '\0')
break;

unsigned int currentLength = 0;

while (str[i] != '\0' && !isSpace(str[i]))
{
currentLength++;
i++;
}

totalLength += currentLength;
wordCount++;
}

if (wordCount == 0)
return 0;

return (totalLength + wordCount / 2) / wordCount;
}
21 changes: 20 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
// Copyright 2022 UNN-IASR
#include "fun.h"

int main() {
#include <iostream>

int main()
{
const char *s1 = "abc test12 hello world7 code";
const char *s2 = "Apple Orange banana Cat Dog X Yz John Smith A1 Test";
const char *s3 = " one three seven ";

std::cout << "Строка 1: \"" << s1 << "\"" << std::endl;
std::cout << "faStr1 = " << faStr1(s1) << std::endl;
std::cout << std::endl;

std::cout << "Строка 2: \"" << s2 << "\"" << std::endl;
std::cout << "faStr2 = " << faStr2(s2) << std::endl;
std::cout << std::endl;

std::cout << "Строка 3: \"" << s3 << "\"" << std::endl;
std::cout << "faStr3 = " << faStr3(s3) << std::endl;
std::cout << std::endl;

return 0;
}
Loading