Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. //1) в заданном тексте найти самую длинную фразу и самое длинное слово.
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <string.h>
  5.  
  6. int main(){
  7.  
  8.     printf("Input text: \n");
  9.  
  10.     char longest_word[50] = {};
  11.     char longest_phrase[255] = {};
  12.     char buf_word[50];
  13.     char buf_phrase[255];
  14.  
  15.     char c;
  16.     int index_word = 0;
  17.     int index_phrase = 0;
  18.  
  19.  
  20.     do{
  21.         c = getche();
  22.         if(c != ' ')
  23.             buf_word[index_word++] = c;
  24.         else{
  25.             buf_word[index_word] = 0;
  26.             if(strlen(longest_word) < strlen(buf_word))
  27.                 strcpy(longest_word, buf_word);
  28.             index_word = 0;
  29.         }
  30.         if(c != '.')
  31.             buf_phrase[index_phrase++] = c;
  32.         else{
  33.             buf_phrase[index_phrase] = 0;
  34.             if(strlen(longest_phrase) < strlen(buf_phrase))
  35.                 strcpy(longest_phrase, buf_phrase);
  36.             index_phrase = 0;
  37.         }
  38.     }while(c != 13);
  39.  
  40.     printf("\nlongest word: %s\n", longest_word);
  41.     printf("longest phrase: %s\n", longest_phrase);
  42.  
  43.     getch();
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement