Translate

Views

Wednesday, June 14, 2023

Solution UVA: 12626 - I ❤ Pizza

 

 Last Submissions
  Problem  VerdictLangTimeBestRankSubmit Time
 | discuss12626 - I ❤ Pizza AcceptedC++110.0000.00017912 mins ago

Problem: 12626
Suggest:
- The key to unlocking the problem is to use a data structure to count the frequency of each character in the string 'MARGIT.' (You can use an array or an unordered_map in your code)

#include<bits/stdc++.h>
using namespace std;

string pizza="MARGIT";
int t;
string s;

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);

    cin >> t;
    while(t--){
        cin >> s;
        unordered_map<char, int> cnt;
        for(int i=0; s[i]; i++)
            cnt[s[i]]++;
       
        int ans= 1000111000;
        for(int i=0; pizza[i]; i++)
            if (pizza[i]=='A')
                ans=min(ans, cnt['A']/3);
            else
            if (pizza[i]=='R')
                ans=min(ans, cnt['R']/2);
            else
                ans=min(ans, cnt[pizza[i]]);
        cout<<ans<<"\n";                    
    }
   
}

No comments: