Advertisement
jakaria_hossain

codechef - chef and string

Jun 11th, 2020
1,174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define fast()(ios_base::sync_with_stdio(0),cin.tie(NULL));
  5. int main()
  6. {
  7.     fast()
  8.     int t;
  9.     cin>>t;
  10.     while(t--)
  11.     {
  12.         string s;
  13.         int cnt=0,i=0;
  14.         cin>>s;
  15.         int sz=s.size();
  16.         while(i<sz)
  17.         {
  18.             if(s[i]=='x'&& s[i+1]=='y')
  19.             {
  20.                 cnt++;
  21.                 i++;
  22.             }
  23.             else if(s[i]=='y'&& s[i+1]=='x')
  24.             {
  25.                 cnt++;
  26.                 i++;
  27.             }
  28.             i++;
  29.         }
  30.         cout<<cnt<<endl;
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement