Uva 12626 - I ❤ Pizza
কি যে করসি !!!
এইসব এতকিছু না করলেও হইত !
এইসব এতকিছু না করলেও হইত !
// Accepted
/// Header file begin
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <sstream>
#include <set>
#include <list>
#include <stack>
#include<utility>
#include <queue>
#include <algorithm>
/// End
//..........
/// Macro
#define sf scanf
#define pf printf
#define sfint(a,b) scanf("%d %d",&a,&b)
#define sfl(a,b) scanf("%ld %ld",&a,&b)
#define sfll(a,b) scanf("%lld %lld",&a,&b)
#define sfd(a,b) scanf("%lf %lf",&a,&b)
#define sff(a,b) scanf("%f %f",&a,&b)
#define lp1(i,n) for(i=0;i<n;i++)
#define lp2(i,n) for(i=1;i<=n;i++)
#define mem(c,v) memset(c,v,sizeof(c))
#define cp(a) cout<<" "<<a<<" "<<endl
#define nl puts("")
#define sq(x) ((x)*(x))
#define all(x) x.begin(),x.end()
#define reall(x) x.rbegin(),x.rend()
#define sz size()
#define gc getchar()
#define pb push_back
/// End.........
/// Size
#define mx7 20000100
#define mx6 1500000
#define mx5 100005
#define mx4 1000100
#define inf 1<<30 //infinity value
#define eps 1e-9
#define mx (65540)
#define mod 1000000007
#define pi acos(-1.0)
/// Macros for Graph
#define white 0
#define gray 1
#define black -1
#define nil -2
using namespace std;
//..................................................................................................................
typedef long long LL;
typedef long L;
typedef unsigned long long ull;
typedef unsigned long ul;
typedef unsigned int ui;
typedef pair<int, int> pii;
map<int,int>mpii;
map<char,int>mpc;
map<string,int>mpsi;
map<bool,int>mpbi;
template<class T> T gcd(T a, T b ) {return b<=0?a:gcd(b,a%b);}
template<class T> T large(T a, T b ) {return a>b?a:b;}
template<class T> T small(T a, T b ) {return a<b?a:b;}
template<class T> T diffrnce(T a, T b) {return a-b<0?b-a:a-b;}
/*
M A R G A R I T A
A-3; R-2; I-1; T-1; G-1; M-1;
*/
struct my
{
char ch;
int hw;
};
my ar[600+9];
struct margarita
{
char c;
int n;
};
margarita mar[12];
struct again
{
char chr;
int num;
};
again ary[600+9];
bool cmp(my a, my b)
{
return a.hw > b.hw;
}
int main()
{
mar[0].c='A';mar[0].n=3;
mar[1].c='R';mar[1].n=2;
mar[2].c='M';mar[2].n=1;
mar[3].c='G';mar[3].n=1;
mar[4].c='I';mar[4].n=1;
mar[5].c='T';mar[5].n=1;
//for(int i=0;i<5;i++)cout << mar[i].c << " " << mar[i].n << " ";
map<char,int>mci;
map<char,bool>mbc;
vector<int>v;
string s;
int t;
sf("%d\n",&t);
while(t--)
{
cin >> s;
int len=s.size(),arylen=0;
mci.clear();
mbc.clear();
v.clear();
for(int i=0;i<len;i++)
{
mci[s[i]]++;
ar[i].ch=s[i];
ar[i].hw=mci[s[i]];
}
sort(ar,ar+len,cmp);
for(int i=0;i<len;i++)
{
if(!mbc[ar[i].ch])
{
ary[arylen].chr=ar[i].ch;
ary[arylen++].num=ar[i].hw;
}
mbc[ar[i].ch]=true;
//ar[i].hw=0;
}
//for(int i=0;i<arylen;i++)cout << ary[i].chr << " - " << ary[i].num << " "; nl;
int s=0;
for(int i=0;i<6;i++)
{
for(int j=0;j<arylen;j++)
{
if(mar[i].c == ary[j].chr)
{
if(ary[j].num >= mar[i].n)
{
//pf("%c ",mar[i].c);
v.push_back(ary[j].num/mar[i].n);
s++;
}
}
}
}
//nl;
sort(all(v)); //cout << "s = " << s;
//for(int i=0;i<v.size();i++)cout << v[i] << " ";
//nl;
s<6?pf("0\n"):pf("%d\n",v[0]);
}
return 0;
}
/*
AAAAAAMMRRTITIGGRRRRRRRR -> 2
AMARGITA -> 0
BOLOGNESACAPRICHOSATOMATERA -> 1
ABCDEFGHIJKLMNOPQRSTUVWXYZ -> 0
AAAAAAAAAAAMMMMMMMGGGGGGGGGGGGRRRRRIIIIIIIIIIITTTTTTTTTTTTT -> 2
*/
Comments
Post a Comment