From 81302f33b0d08eab171738092fe0244016ff972f Mon Sep 17 00:00:00 2001 From: GreenTeaDude Date: Sun, 29 Mar 2026 19:37:12 +0300 Subject: [PATCH 1/4] Update fun.cpp --- src/fun.cpp | 146 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 138 insertions(+), 8 deletions(-) diff --git a/src/fun.cpp b/src/fun.cpp index 418f426..a8e1daf 100644 --- a/src/fun.cpp +++ b/src/fun.cpp @@ -1,14 +1,144 @@ -// Copyright 2022 UNN-IASR -#include "fun.h" +#ifndef FUN_H +#define FUN_H -unsigned int faStr1(const char *str) { - return 0; +unsigned int faStr1(const char *str); +unsigned int faStr2(const char *str); +unsigned int faStr3(const char *str); + +#endif + + +#include + + +bool isSpace(char c) +{ + return c == ' '; +} + +bool isDigit(char c) +{ + return c >= '0' && c <= '9'; +} + +bool isUpperLatin(char c) +{ + return c >= 'A' && c <= 'Z'; +} + +bool isLowerLatin(char c) +{ + return c >= 'a' && c <= 'z'; } -unsigned int faStr2(const char *str) { - return 0; +// Задача 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; } -unsigned int faStr3(const char *str) { - return 0; +// Задача 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; } From 941283eff7aa4684ab3dc341ed2ebecceec34128 Mon Sep 17 00:00:00 2001 From: GreenTeaDude Date: Sun, 29 Mar 2026 19:39:00 +0300 Subject: [PATCH 2/4] Update main.cpp --- src/main.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 89bbf61..d0b4683 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,25 @@ // Copyright 2022 UNN-IASR #include "fun.h" -int main() { +#include + +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; } From 4f6c940285e8295989951b9fa46e9767897e6141 Mon Sep 17 00:00:00 2001 From: GreenTeaDude Date: Sun, 29 Mar 2026 19:49:38 +0300 Subject: [PATCH 3/4] Update fun.cpp --- src/fun.cpp | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/fun.cpp b/src/fun.cpp index a8e1daf..d9937d4 100644 --- a/src/fun.cpp +++ b/src/fun.cpp @@ -1,15 +1,4 @@ -#ifndef FUN_H -#define FUN_H - -unsigned int faStr1(const char *str); -unsigned int faStr2(const char *str); -unsigned int faStr3(const char *str); - -#endif - - -#include - +#include "fun.h" bool isSpace(char c) { @@ -31,7 +20,8 @@ bool isLowerLatin(char c) return c >= 'a' && c <= 'z'; } -// Задача 1: +// Задача 1 + unsigned int faStr1(const char *str) { if (str == nullptr) @@ -64,8 +54,7 @@ unsigned int faStr1(const char *str) return count; } -// Задача 2: - +// Задача 2 unsigned int faStr2(const char *str) { if (str == nullptr) @@ -107,7 +96,8 @@ unsigned int faStr2(const char *str) return count; } -// Задача 3: +// Задача 3 + unsigned int faStr3(const char *str) { if (str == nullptr) From 814bbf01a1ca6e1a514e48365d861d0074afd85b Mon Sep 17 00:00:00 2001 From: GreenTeaDude Date: Sun, 29 Mar 2026 19:50:05 +0300 Subject: [PATCH 4/4] Update main.cpp