Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.30 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <progbase/console.h>
  6. int main(void)
  7. {
  8.     puts("=================================================================================================================");
  9.     Console_setCursorAttribute(BG_RED);
  10.     puts("1.Вивести текст повністю у консолі та загальну кількість символів у тексті.");
  11.     Console_setCursorAttribute(BG_DEFAULT);
  12.     char buffer[] = "Cats have been domesticated for around 4,000 years. While they were once valued for their hunting abilities, they are now valued for their companionship and loving behaviour.\nWhile not well known, the collective nouns used for cats and kittens are a clowder of cats and a kindle of kittens.\nOur domestic cats are known as little cats. They differ from large cats such as lions and tigers because they are naturally active at night and can purr.\nCats are now the most popular pet in the UK and in the US.\n";
  13.     int size = sizeof(buffer) / sizeof(buffer[0]);
  14.     puts(buffer);
  15.     printf("Number of elements: %i\n", size);
  16.     puts("=================================================================================================================");
  17.     Console_setCursorAttribute(BG_BLUE);
  18.     puts("2.Вивести текст без пробільних символів та символів пунктуації та кількість виведених символів.");
  19.     Console_setCursorAttribute(BG_DEFAULT);
  20.     int count = 0;
  21.     //x - other sybmols
  22.     for (int i = 0; i < size; i++)
  23.     {
  24.         if (isalnum(buffer[i]))
  25.         {
  26.             printf("%c", buffer[i]);
  27.         }
  28.         else
  29.         {
  30.             count++;
  31.         }
  32.     }
  33.     puts(" ");
  34.     //x = number of  alphanumeric symbols
  35.     int x = size - count;
  36.     printf("Number of just alphanumeric symbols: %i\n", x);
  37.     puts("=================================================================================================================");
  38.     Console_setCursorAttribute(BG_GREEN);
  39.     Console_setCursorAttribute(FG_BLACK);
  40.     puts("3.Вивести всі речення тексту, кожне речення із нового рядка та із відміткою про кількість символів у виведеному реченні. ");
  41.     Console_setCursorAttribute(BG_DEFAULT);
  42.     Console_setCursorAttribute(FG_DEFAULT);
  43.     count = 0;
  44.     int count2 = 0;
  45.     puts("------------------------------------------------------------------------------");
  46.     for (int i = 0; i < size; i++)
  47.     {
  48.         if (buffer[i] != '.')
  49.         {
  50.             count++;
  51.             printf("%c", buffer[i]);
  52.         }
  53.         else
  54.         {
  55.             printf(".");
  56.             count2 = count;
  57.             count = 0;
  58.             printf("\nNumber symbols in this sentence :%i\n", count2);
  59.             printf("------------------------------------------------------------------------------\n");
  60.         }
  61.     }
  62.     puts("=================================================================================================================");
  63.     Console_setCursorAttribute(BG_INTENSITY_YELLOW);
  64.     Console_setCursorAttribute(FG_BLACK);
  65.     puts("4.Вивести загальну кількість слів у тексті");
  66.     Console_setCursorAttribute(BG_DEFAULT);
  67.     Console_setCursorAttribute(FG_DEFAULT);
  68.     count = 0;
  69.     for (int i = 0; i < size; i++)
  70.     {
  71.         if (!(isalnum(buffer[i])))
  72.         {
  73.             count++;
  74.         }
  75.     }
  76.     printf("Number of words is : %i\n", count);
  77.     puts("=================================================================================================================");
  78.     Console_setCursorAttribute(BG_CYAN);
  79.     Console_setCursorAttribute(FG_BLACK);
  80.     puts("5.У одному рядку, через кому і один пробіл, вивести всі слова, що мають довжину > 3 символів. Також вивести загальну кількість таких слів.");
  81.     Console_setCursorAttribute(BG_DEFAULT);
  82.     Console_setCursorAttribute(FG_DEFAULT);
  83.     count = 0;
  84.     int c = 0;
  85.     // c counts number of letters
  86.     for (int i = 0; i < size; i++)
  87.     {
  88.         if (isalnum(buffer[i]))
  89.         {
  90.             c = 0;
  91.             while (isalpha(buffer[i + 1]))
  92.             {
  93.                 c++;
  94.                 i++;
  95.             }
  96.             if (c >= 3)
  97.             {
  98.                 for (int k = i - c; k <= i; k++)
  99.                 {
  100.                     count++;
  101.                     printf("%c", buffer[k]);
  102.                 }
  103.                 printf(", ");
  104.             }
  105.         }
  106.     }
  107.     printf("\nNumber of words is : %i\n", count);
  108.     puts("=================================================================================================================");
  109.     Console_setCursorAttribute(BG_MAGENTA);
  110.     Console_setCursorAttribute(FG_WHITE);
  111.     puts("6.У одному рядку, через кому і один пробіл, вивести всі слова, у яких є хоча б дві голосні літери підряд. Також вивести загальну кількість таких слів.");
  112.     Console_setCursorAttribute(BG_DEFAULT);
  113.     Console_setCursorAttribute(FG_DEFAULT);
  114.     char vowel[] = "aeyuioAEYUIO";
  115.     int vowelLength = strlen(vowel);
  116.     int isvowel1 = 0;
  117.     int isvowel2 = 0;
  118.     count = 0;
  119.     int i2 = 0;
  120.     for (int i = 0; i < size; i++)
  121.     {
  122.         if (isalpha(buffer[i]))
  123.         {
  124.             isvowel1 = 0;
  125.             isvowel2 = 0;            
  126.             for (int j = 0; j < vowelLength; j++)
  127.             {
  128.                 if (buffer[i] == vowel[j])
  129.                 {
  130.                     isvowel1 = 1;
  131.                     break;
  132.                 }
  133.             }
  134.             if (isvowel1)
  135.             {
  136.                 for (int j = 0; j < vowelLength; j++)
  137.                 {
  138.                     if (buffer[i + 1] == vowel[j])
  139.                     {
  140.                         isvowel2 = 1;
  141.                         break;
  142.                     }
  143.                 }
  144.             }
  145.             if (isvowel2)
  146.             {
  147.                
  148.                 count++;
  149.             }
  150.         }
  151.     }
  152.     printf("\n%i\n", count);
  153.  
  154.     return 0;
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement