Created
May 26, 2025 16:35
-
-
Save vlaleli/ded39fa4504392432be803204e592b3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cstdio> | |
| #include <cctype> | |
| bool isVowel(char ch) { | |
| if (ch >= 'A' && ch <= 'Z') ch += 'a' - 'A'; | |
| return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || | |
| ch == 'а' || ch == 'е' || ch == 'є' || ch == 'и' || ch == 'і' || | |
| ch == 'ї' || ch == 'о' || ch == 'у' || ch == 'ю' || ch == 'я'; | |
| } | |
| bool isConsonant(char ch) { | |
| if (ch >= 'A' && ch <= 'Z') ch += 'a' - 'A'; | |
| if ((ch >= 'a' && ch <= 'z') || (unsigned char)ch >= 128) | |
| return !isVowel(ch); | |
| return false; | |
| } | |
| int main() { | |
| FILE* input = fopen("input.txt", "r"); | |
| if (!input) { | |
| printf("Не удалось открыть input.txt\n"); | |
| return 1; | |
| } | |
| FILE* output = fopen("stats.txt", "w"); | |
| if (!output) { | |
| printf("Не удалось создать stats.txt\n"); | |
| fclose(input); | |
| return 1; | |
| } | |
| int chars = 0, lines = 0, vowels = 0, consonants = 0, digits = 0; | |
| int ch; | |
| bool lastWasNewline = true; | |
| while ((ch = fgetc(input)) != EOF) { | |
| chars++; | |
| if (ch == '\n') { | |
| lines++; | |
| lastWasNewline = true; | |
| } else { | |
| lastWasNewline = false; | |
| } | |
| if (ch >= '0' && ch <= '9') digits++; | |
| else if (isVowel((char)ch)) vowels++; | |
| else if (isConsonant((char)ch)) consonants++; | |
| } | |
| if (chars > 0 && !lastWasNewline) lines++; | |
| fprintf(output, "Кількість символів: %d\n", chars); | |
| fprintf(output, "Кількість рядків: %d\n", lines); | |
| fprintf(output, "Кількість голосних: %d\n", vowels); | |
| fprintf(output, "Кількість приголосних: %d\n", consonants); | |
| fprintf(output, "Кількість цифр: %d\n", digits); | |
| fclose(input); | |
| fclose(output); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment