Page 1 of 1

12626 - I ❤ Pizza

Posted: Thu Mar 20, 2014 12:16 pm
by ashek.rahman
What is problem in my code? I got Wrong answer. Please help.

Code: Select all

#include <iostream>
#include <stdio.h>
#include <map>

using namespace std;

int main()
{
    int n, pn;
    int inum[6] = {3, 1, 1, 1, 2, 1};
    string s;
    map <char, int> ing;
    std::map<char,int>::iterator it;
    cin >> n;
    getchar();
    for (int i=0; i<n; i++){
        pn = 100;
        getline(cin, s, '\n');
        //cout << s << endl;
        for (int j=0; j<s.length(); j++){
            if (s[j]=='M' || s[j]=='A' || s[j]=='R' || s[j]=='G' || s[j]=='I' || s[j]=='T'){
                ing[s[j]]++;
            }
        }
        int k=0;
        for (it=ing.begin(); it!=ing.end(); it++, k++){
            if (it->second/inum[k]<pn){
                pn = it->second/inum[k];
            }
        }
        cout << pn << endl;
        ing.clear();
    }
    return 0;
}

Re: 12626

Posted: Thu Mar 20, 2014 8:16 pm
by brianfry713
Try input:

Code: Select all

1
B

Re: 12626

Posted: Mon Mar 24, 2014 7:31 am
by ashek.rahman
Changed my code. Still got wrong answer :(

Code: Select all

#include <iostream>
#include <stdio.h>
#include <map>

using namespace std;

int main()
{
    int n, pn;
    int inum[6] = {3, 1, 1, 1, 2, 1};
    string s;
    map <char, int> ing;
    std::map<char,int>::iterator it;
    cin >> n;
    getchar();
    for (int i=0; i<n; i++){
        pn = 100;
        getline(cin, s, '\n');
        //cout << s << endl;
        for (int j=0; j<s.length(); j++){
            if (s[j]=='M' || s[j]=='A' || s[j]=='R' || s[j]=='G' || s[j]=='I' || s[j]=='T'){
                ing[s[j]]++;
            }
        }
        int k=0;
        for (it=ing.begin(); it!=ing.end(); it++, k++){
            if (it->second/inum[k]<pn){
                pn = it->second/inum[k];
            }
        }
        if (ing.empty())
            cout << 0 << endl;
        else
            cout << pn << endl;
        ing.clear();
    }
    return 0;
}

Re: 12626

Posted: Tue Mar 25, 2014 12:46 am
by brianfry713
Try input:

Code: Select all

1
AAA

Re: 12626

Posted: Tue Jul 22, 2014 7:28 am
by uDebug
Replying to follow the thread.

Re: 12626 - I ❤ Pizza

Posted: Sun Aug 31, 2014 9:47 pm
by Shihab
1
AAARRM

IT helped me.MIght help someone else

Re: 12626 - I ❤ Pizza

Posted: Wed Mar 18, 2015 3:36 pm
by rzshiplu_bd
can you suggest me please whats wrong with this code ? :(

Code: Select all

#include<stdio.h>
#include<string.h>
int main(){
    int j,tt,len;
    int a=3,g=1,i=1,m=1,r=2,t=1;
    int a1,g1,i1,m1,r1,t1,min,ma,mg,mi,mm,mr,mt;
    char s[601];
    scanf("%d",&tt);
    while(tt--){
        scanf("%s",&s);
        len = strlen(s);
        if(len<9){
            printf("0\n");
            continue;
        }
        a1=g1=i1=m1=r1=t1=0;
        for(j=0;j<len;j++){
            switch(s[j]){
                case 'A': a1++; break;
                case 'G': g1++; break;
                case 'I': i1++; break;
                case 'M': m1++; break;
                case 'R': r1++; break;
                case 'T': t1++; break;
            }
        }

        if(a1<a || g1<g || i1<i || m1<m || r1<r || t1<t){
            printf("0\n");
            continue;
        }

        min=600;
        ma = a1/a; if(ma<min) min=ma;
        mg = g1/g; if(mg<min) min=mg;
        mi = i1/i; if(mi<min) min=mi;
        mm = m1/m; if(mm<min) min=mm;
        mr = r1/r; if(mr<min) min=mr;
        mt = t1/t; if(mt<min) min=mt;

        printf("%d\n",min);
    }
    return 0;
}