12626 - I ❤ Pizza

All about problems in Volume 126. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
ashek.rahman
New poster
Posts: 8
Joined: Mon Mar 10, 2014 8:18 am

12626 - I ❤ Pizza

Post by ashek.rahman » Thu Mar 20, 2014 12:16 pm

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;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12626

Post by brianfry713 » Thu Mar 20, 2014 8:16 pm

Try input:

Code: Select all

1
B
Check input and AC output for thousands of problems on uDebug!

ashek.rahman
New poster
Posts: 8
Joined: Mon Mar 10, 2014 8:18 am

Re: 12626

Post by ashek.rahman » Mon Mar 24, 2014 7:31 am

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;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12626

Post by brianfry713 » Tue Mar 25, 2014 12:46 am

Try input:

Code: Select all

1
AAA
Check input and AC output for thousands of problems on uDebug!

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 12626

Post by uDebug » Tue Jul 22, 2014 7:28 am

Replying to follow the thread.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

Shihab
New poster
Posts: 33
Joined: Thu Jun 13, 2013 1:19 pm

Re: 12626 - I ❤ Pizza

Post by Shihab » Sun Aug 31, 2014 9:47 pm

1
AAARRM

IT helped me.MIght help someone else

rzshiplu_bd
New poster
Posts: 1
Joined: Wed Mar 18, 2015 3:33 pm

Re: 12626 - I ❤ Pizza

Post by rzshiplu_bd » Wed Mar 18, 2015 3:36 pm

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;
}
Last edited by brianfry713 on Tue Mar 31, 2015 12:23 am, edited 1 time in total.
Reason: Added code block

Post Reply

Return to “Volume 126 (12600-12699)”