154A Codeforces - Hometask


154A Codeforces - Hometask




Solution in c++

#include <bits/stdc++.h>

using namespace std;

string inp;
char a1,a2;
int p,sz,sol;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>inp>>p;
    sz=inp.size();
    int h1=0,h2=0;
    while(p--)
    {
        cin>>a1>>a2;
        for(int i=0;i<sz;i++)
        {
            if(inp[i]==a1)h1++;
            else if(inp[i]==a2)h2++;
            else sol+=min(h1,h2),h1=h2=0;
        }
    }
    sol+=min(h1,h2);
    cout<<sol;
    return 0;
}

Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق