Advertisement
Scratius

MINSlovo

Jan 20th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int poisk(char* str, int ch) {
  4.     int i = 0;
  5.     while (str[i]) {
  6.         if (str[i] == ch) {
  7.             return i;
  8.         }
  9.         i++;
  10.     }
  11.     return -1;
  12. }
  13.  
  14. int minim(char* str) {
  15.     int i = 0;
  16.     int min = 1000;
  17.     int inword = 1;
  18.     int c = 0;
  19.     char sep[] = " ,.!?\n\t\0";
  20.     while (str[i]) {
  21.         if (poisk(sep, str[i]) != -1) {
  22.             if (inword) {
  23.                 if (c < min && c != 0) {
  24.                     min = c;
  25.                 }
  26.                 c = 0;
  27.                 inword = 0;
  28.  
  29.             }
  30.         }
  31.         else {
  32.             c++;
  33.             inword = 1;
  34.         }
  35.  
  36.         i++;
  37.     }
  38.     if (inword) {
  39.         if (c < min && c != 0) {
  40.             min = c;
  41.         }
  42.     }
  43.     return min;
  44. }
  45.  
  46. int main()
  47. {
  48.     int const size = 50;
  49.     char str[size] = " ";
  50.     char str1[size];
  51.  
  52.     int i = 0;
  53.     int min = 1000;
  54.     while (str[0] != '\n') {
  55.         fgets(str, size, stdin);
  56.         if (minim(str) < min) {
  57.             min = minim(str);
  58.             while (str[i] != '\n') {
  59.                 str1[i] = str[i];
  60.                 i++;
  61.             }
  62.             str1[i] = '\0';
  63.             i = 0;
  64.  
  65.         }
  66.  
  67.     }
  68.     printf("%s", str1);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement