Advertisement
STANAANDREY

T pb3/66

Oct 5th, 2019
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <stdio.h>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.  
  9.     char c, text[256], s[256][256];
  10.     cin >> c;
  11.     getchar();
  12.     gets(text);
  13.  
  14.     int n = strlen(text);
  15.     int k = 0;
  16.     for (int i = 0, j = 0; i <= n; i++)
  17.     {
  18.         if (text[i] == ' ' || !text[i])
  19.         {
  20.             if (!i || text[i - 1] != ' ')
  21.             {
  22.                 strncpy(s[k], text + i - j, j);
  23.                 s[k][j] = 0;
  24.                 k++;
  25.                 j = 0;
  26.             }
  27.         }
  28.         else
  29.             j++;
  30.     }
  31.  
  32.     cout << "cuvinte ce contin '" << c << "' : ";
  33.     int nr = 0;
  34.     for (int i = 0; i < k; i++)
  35.         if (strchr(s[i], c))
  36.         {
  37.             nr++;
  38.             cout << s[i] << ' ';
  39.         }
  40.  
  41.     cout << endl << "nr: " << nr;
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement