Advertisement
SabirSazzad

Selective Word repetation Count

Feb 26th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. using namespace std;
  4.  
  5. class SWRC
  6. {
  7. private:
  8.     char paragraph[100];
  9. public:
  10.     void setPara()
  11.     {
  12.         gets(paragraph);
  13.     }
  14.     void CountSelectiveWord()
  15.     {
  16.         char word[100] = "abc";
  17.         int Count=0,i=0,j=0,k=0;
  18.         for(i=0; paragraph[i] != '\0'; i++)
  19.         {
  20.             if(paragraph[i] == 'a' && paragraph[i+1] == 'b' && paragraph[i+2]== 'c')
  21.             {
  22.                 Count++;
  23.                 if((paragraph[i+3]>=65 && paragraph[i+3]<=122) || (paragraph[i-1]>=65 && paragraph[i-1]<=122))
  24.                 {
  25.                     Count--; // if there is another letter after or before 'abc' then it will skip (Using ASCII value)
  26.                             // as example 'xabc' or 'abcz' will not count
  27.                 }
  28.  
  29.             }
  30.  
  31.         }
  32.         cout << "\nNumber of 'abc' Repetition: " << Count <<endl;
  33.     }
  34. };
  35. int main()
  36. {
  37.     SWRC obj;
  38.     cout << "Input paragraph: ";
  39.     obj.setPara();
  40.     obj.CountSelectiveWord();
  41.  
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement