Codeforces 1146A. Love "A" Solution

Solve in C++:


#include<bits/stdc++.h>
using namespace std;
main()
{

    int a=0,i,l,r,ex=0,c=0;
    char s[101];
    while(cin>>s)
    {
        l=strlen(s);
        for(i=0; i<l; i++)
        {
            if(s[i]=='a')
                a++;
            else
                ex++;
        }

        if(a>ex)
            cout<<a+ex<<endl;
        else if(a==ex)
            cout<<a+ex-1<<endl;
        else
        {
            while(1)
            {
                ex--;
                if(a>ex)
                {
                    c=1;
                    break;
                }
            }
            if(c==1)
                cout<<a+ex<<endl;


        }
        a=0,ex=0,c=0;
    }



}

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.