Accepted solution

UVA 12626 - I ❤ Pizza Solution in C++.

Open original problem
Source code

#include <iostream>

using namespace std;

int main()

{

    string str;

    int n;

    cin>>n;

    while(n>0)

    {

        cin>>str;

        int M=0,R=0,G=0,I=0,T=0,A=0;

        int count=0;

        for(int i=0; str[i]!='�'; i++)

        {

            if(str[i]=='M')M++;

            else if(str[i]=='R')R++;

            else if(str[i]=='G')G++;

            else if(str[i]=='I')I++;

            else if(str[i]=='T')T++;

            else if(str[i]=='A')A++;

        }

        while(1)

        {

            if(A>=3 && M>=1 && R>=2 && G>=1 && I>=1 && T>=1 )

            {

                count++;

                A-=3;

                M-=1;

                R-=2;

                G-=1;

                I-=1;

                T-=1;

            }

            else break;

        }

        cout<<count<<endl;

        n--;

    }

    return 0;

}
Join the discussion

Add your comment