Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- using namespace std;
- class SWRC
- {
- private:
- char paragraph[100];
- public:
- void setPara()
- {
- gets(paragraph);
- }
- void CountSelectiveWord()
- {
- char word[100] = "abc";
- int Count=0,i=0,j=0,k=0;
- for(i=0; paragraph[i] != '\0'; i++)
- {
- if(paragraph[i] == 'a' && paragraph[i+1] == 'b' && paragraph[i+2]== 'c')
- {
- Count++;
- if((paragraph[i+3]>=65 && paragraph[i+3]<=122) || (paragraph[i-1]>=65 && paragraph[i-1]<=122))
- {
- Count--; // if there is another letter after or before 'abc' then it will skip (Using ASCII value)
- // as example 'xabc' or 'abcz' will not count
- }
- }
- }
- cout << "\nNumber of 'abc' Repetition: " << Count <<endl;
- }
- };
- int main()
- {
- SWRC obj;
- cout << "Input paragraph: ";
- obj.setPara();
- obj.CountSelectiveWord();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement