Advertisement
cska1312

StrCount

Feb 14th, 2023
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int findStrCount(string str)
  5. {
  6.     int count = 0;
  7.     int n = str.size();
  8.  
  9.     for (int i = 0; i < n - 1; i++)
  10.     {
  11.         if (str[i] + 1 == str[i + 1])
  12.         {
  13.             count++;
  14.             while (str[i] + 1 == str[i + 1])
  15.             {
  16.                 i++;
  17.             }
  18.         }
  19.     }
  20.     return count;
  21. }
  22.  
  23. int main()
  24. {
  25.     string str;
  26.     cin >> str;
  27.  
  28.     cout << findStrCount(str) << endl;
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement