Last Submissions | ||||||
---|---|---|---|---|---|---|
Problem | Verdict | Lang | Time | Best | Rank | Submit Time |
| discuss12626 - | Accepted | C++11 | 0.000 | 0.000 | 1791 | 2 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:
Post a Comment