Codeforces Round #780 (Div. 3) 1660C - Get an Even String Solution




  Problem Link :  https://codeforces.com/contest/1660/problem/C

Solution in C++:

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long  i,t,j;
    cin>>t;
    while(t--)
    {
        string s,r;
        map<char,int>mp;
        cin>>s;
        for(i=0; i<s.size()-1; i++)
        {
          if(s[i]==s[i+1])
          {
              r+=s[i];
              r+=s[i+1];
              i++;
          }
          else
          {
              while(i<s.size()&&mp[s[i]]!=1)
              {
                  mp[s[i]]=1;
                  i++;
              }
              if(i<s.size())
              {
                  r+=s[i];
                  r+=s[i];
              }
              mp.clear();
          }
        }
         cout<<s.size()-r.size()<<endl;
    }
}
 


No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.