kej

4.Дан текст, состоящий из слов, разделенных пробелами. Подсч

kej
Mar 1st, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. int main ()
  5. {
  6.     int counter2 = 0;
  7.     int counter =0;
  8.     int prevCounter2 = 0;
  9.     char str[256];
  10.     cin.getline(str, 256);
  11.     char c;
  12.     cout<<"Enter symbol: ";
  13.     cin>>c;
  14.    
  15.    
  16.  
  17.   char * pch = strtok (str," ");
  18.  
  19.   while (pch != NULL)                        
  20.   {
  21.       prevCounter2 = counter2;
  22.       for (int i=0;i<strlen(pch);i++)
  23.       {
  24.          
  25.          if (pch[i] == c)
  26.              counter++;
  27.          
  28.       }
  29.      
  30.       if (counter == 2){
  31.           prevCounter2 = counter2;
  32.           counter2++;
  33.           for (int i=0;i<strlen(pch);i++)
  34.           {
  35.           if (!isalpha(pch[i]))
  36.           {
  37.               counter2= prevCounter2;
  38.           }
  39.           }
  40.       counter = 0;
  41.       pch = strtok (NULL, " ");
  42.   }
  43.   }
  44.     cout<<"Symbol "<<c<<" 2 times in words: "<<counter2<<endl;
  45.  
  46. }
Add Comment
Please, Sign In to add comment