Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.34 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define STRING "Hello, Ara! I am glad to see you, my friend! How are you doooing? Goood!"
  6.  
  7. int qtyWordsInStr(char *str);
  8. void InWord3_O(char *str);
  9. void InWord3_Syll(char *str);
  10. void streamWords(char *str);
  11. void polyndromWords(char *str);
  12. void superWordsPrint(char *str);
  13.  
  14. void main() {
  15.     int n = strlen(STRING) + 1;
  16.     char *str = malloc(sizeof(char) * n);
  17.     strcpy(str, STRING);
  18.  
  19.     printf("There are %d words in String\n", qtyWordsInStr(str));
  20.     InWord3_O(str);
  21.     InWord3_Syll(str);
  22.     streamWords(str); printf("%s\n",str);
  23.     polyndromWords(str);
  24.     superWordsPrint(str);
  25.    
  26.     free(str);
  27. }
  28.  
  29. int qtyWordsInStr(char *str){
  30.     int qtyWords=0;
  31.     int ukLetter=0;
  32.     int i=0;
  33.     do{
  34.         if (str[i]<91 && str[i]>64 || str[i]>96 && str[i]<123){
  35.             ukLetter=1; i++; continue;
  36.         }
  37.         if (ukLetter==1){
  38.             qtyWords++; ukLetter=0;
  39.         }
  40.         i++;
  41.     } while(str[i]);
  42.    
  43.     return qtyWords;
  44. }
  45.  
  46. void InWord3_O(char *str){
  47.     int i=0;
  48.     int ukEnd=0;
  49.     int ukO=0;
  50.     int ukLetter=0;
  51.    
  52.     do{
  53.         if (str[ukEnd]<91 && str[ukEnd]>64 || str[ukEnd]>96 && str[ukEnd]<123){
  54.             if (str[ukEnd]=='o'||str[ukEnd]=='O') ukO++;
  55.             ukLetter=1; ukEnd++; continue;
  56.         }
  57.         if (ukLetter==1 && ukO==3){
  58.             for (; str[i], i<ukEnd; i++) printf("%c",str[i]);
  59.             printf(" ");
  60.         }
  61.         ukEnd++; i=ukEnd; ukLetter=0; ukO=0;
  62.     } while(str[i]);
  63.    
  64.     printf("\n");
  65. }
  66.  
  67. void InWord3_Syll(char *str){
  68.     int i=0;
  69.     int ukSyl=0;
  70.     int ukEnd=0;
  71.     char *vowels="euioaEUIOA";
  72.    
  73.     do{
  74.         if (str[ukEnd]<91 && str[ukEnd]>64 || str[ukEnd]>96 && str[ukEnd]<123){
  75.             int t,ukVow=0;
  76.             for (t=0; vowels[t]; t++)
  77.                 if (str[ukEnd]==vowels[t]){
  78.                     ukVow=1;
  79.                     break;
  80.                 }
  81.             if (ukVow==1) ukSyl++;
  82.             ukEnd++; continue;
  83.         }
  84.         if (ukSyl==3){
  85.             for (; str[i], i<ukEnd; i++) printf("%c",str[i]);
  86.             printf(" ");
  87.         }
  88.         ukEnd++; i=ukEnd; ukSyl=0;
  89.     } while(str[i]);
  90.  
  91.     printf("\n");
  92. }
  93.  
  94. void streamWords(char *str){
  95.     int i,k,t,uk=0;
  96.     int qtyWords=0;
  97.     int maxLong=0;
  98.     int wordLong=0;
  99.    
  100.     for (i=0; str[i]; i++){
  101.         if (str[i]<91 && str[i]>64 || str[i]>96 && str[i]<123){
  102.             uk=1;
  103.             wordLong++;
  104.         }
  105.         else{
  106.             if (uk==1){
  107.                 qtyWords++;
  108.                 if (wordLong>maxLong) maxLong=wordLong;
  109.                 uk=0; wordLong = 0;
  110.             }
  111.         }
  112.     }
  113.    
  114.     maxLong++;
  115.     char wordsArr[qtyWords][maxLong];
  116.    
  117.     char *pointer_to_char = str;
  118.     uk = 0;
  119.     int num_of_incorrect_chars;
  120.     for (i = 0; i < qtyWords; i++) {
  121.         wordLong = 0;
  122.         while (str[uk] < 91 && str[uk] > 64 || str[uk] > 96 && str[uk] < 123){
  123.             if (str[uk] < 91 && str[uk] > 64) str[uk]+=32;
  124.             uk++;
  125.             wordLong++;
  126.         }
  127.        
  128.         memcpy(&wordsArr[i][0], pointer_to_char, sizeof(char)*wordLong);
  129.        
  130.         num_of_incorrect_chars = 0;
  131.        
  132.         while (str[uk] != '\0' && !(str[uk] < 91 && str[uk]>64 || str[uk] > 96 && str[uk] < 123)){
  133.             uk++;
  134.             num_of_incorrect_chars++;
  135.         }
  136.         pointer_to_char += (num_of_incorrect_chars + wordLong);
  137.  
  138.         wordsArr[i][wordLong]='\0';
  139.     }
  140.    
  141.     for (i=0; i<qtyWords; i++)
  142.         for (k=0; k<qtyWords-i-1; k++)
  143.             if (strcmp(wordsArr[k],wordsArr[k+1])>0){
  144.                 for (t=0; t<maxLong; t++){
  145.                     char c=wordsArr[k][t];
  146.                     wordsArr[k][t]=wordsArr[k+1][t];
  147.                     wordsArr[k+1][t]=c;
  148.                 }
  149.             }
  150.    
  151.     uk=-1;
  152.     for (i=0; i<qtyWords;i++){
  153.         for(k=0; wordsArr[i][k]; k++){
  154.             uk++;
  155.             str[uk]=wordsArr[i][k];
  156.         }
  157.         uk++;
  158.         str[uk]=' ';
  159.     }
  160.     str[uk+1]='\0';
  161. }
  162.  
  163. void polyndromWords(char *str){
  164.     int i,k;
  165.     int havePol=0;
  166.    
  167.     for (i=0; str[i]; i++){
  168.         int wordLong=0;
  169.         int uk=i;
  170.         int ukPol=1;
  171.        
  172.         while (str[uk] < 91 && str[uk]>64 || str[uk] > 96 && str[uk] < 123){
  173.             wordLong++;
  174.             uk++;
  175.         }
  176.        
  177.         for (uk=0; uk<=wordLong/2; uk++)
  178.             if (str[i+uk]!=str[i+wordLong-uk-1] && str[i+uk]-32!=str[i+wordLong-uk-1]
  179.                 && str[i+uk]!=str[i+wordLong-uk-1]-32){
  180.                 ukPol=0;
  181.                 break;
  182.             }
  183.        
  184.         if (ukPol==1){
  185.             for (uk=0; uk<wordLong; uk++, i++) printf("%c",str[i]);
  186.             printf(" ");
  187.             havePol=1;
  188.         }
  189.         else i+=wordLong;
  190.     }
  191.     if (havePol==0) printf("No polyndrom words");
  192.     printf("\n");
  193. }
  194.  
  195. void superWordsPrint(char *str){
  196.     int i;
  197.    
  198.     for (i=0; str[i]; i++){
  199.         int qtyLetters=0;
  200.        
  201.         int ukEnd=i;
  202.         while (str[ukEnd]<91 && str[ukEnd]>64 || str[ukEnd]>96 && str[ukEnd]<123) ukEnd++;
  203.        
  204.         int wordLong=ukEnd-i;
  205.         int k,t;
  206.         for (k=0; k<wordLong; k++){
  207.             for (t=i; t<ukEnd; t++) printf("%c",str[t]);
  208.             printf(" ");
  209.         }
  210.         i=ukEnd;
  211.     }
  212.    
  213.     printf("\n");
  214. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement