nikitast

bilet_10

Jan 19th, 2021
435
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7.     char str[255];
  8.     gets_s(str);
  9.     char* ptr = strtok(str, " ");
  10.     int min_ind = 0;
  11.     int min_len = strlen(ptr);
  12.     char min_word[80];
  13.     strcpy(min_word, ptr);
  14.     int max_ind = 0;
  15.     int max_len = strlen(ptr);
  16.     char max_word[80];
  17.     strcpy(max_word, ptr);
  18.     int cnt = 0;
  19.     while (ptr != NULL)
  20.     {  
  21.         if (strlen(ptr) < min_len)
  22.         {
  23.             min_ind = cnt;
  24.             min_len = strlen(ptr);
  25.             strcpy(min_word, ptr);
  26.         }
  27.         if (strlen(ptr) > max_len)
  28.         {
  29.             max_ind = cnt;
  30.             max_len = strlen(ptr);
  31.             strcpy(max_word, ptr);
  32.         }
  33.         ptr = strtok(NULL, " ");
  34.         cnt++;
  35.     }
  36.     printf("%s, ind = %d, len = %d\n", min_word, min_ind, min_len);
  37.     printf("%s, ind = %d, len = %d\n", max_word, max_ind, max_len);
  38. }
RAW Paste Data