Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

Help for "Baking Business" problem

$
0
0

Hi all,

i submitted my code for "baking business problem" - https://www.codechef.com/problems/BAKE It was giving me correct answer for all my test cases but it gives "wrong answer" when i submit

#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<stdlib.h>
using namespace std;

int main()
{
/* The number of inputs*/
int numberOfInputs;

/* The Map storing values of input type I*/
map<int,vector<string> > Imap;

/* The Vector storing values of input type Q*/
vector<string> Qvec;

/*Vector stporing the value of Output*/
vector<int> output;

cin  >> numberOfInputs;

for (int i=0; i< numberOfInputs; i++)
{
 vector<string> inputValues;
 string inputType;
 string productSize;
 string provinceDetail;
 string gender;
 string age;
 string unitsSold;
 cin >> inputType;
 if ( inputType == "I")
 {
    cin >> productSize >> provinceDetail >> gender >> age >> unitsSold;
    inputValues.push_back(productSize);
    inputValues.push_back(provinceDetail);
    inputValues.push_back(gender);
    inputValues.push_back(age);
    inputValues.push_back(unitsSold);
    Imap.insert(pair<int,vector<string> >(i,inputValues) );
 }

 else if(inputType == "Q")
 {
    int result = 0;
    string ageRange;
    cin >> productSize >> provinceDetail >> gender >> ageRange;
    Qvec.push_back(productSize);
    Qvec.push_back(provinceDetail);
    Qvec.push_back(gender);
    Qvec.push_back(ageRange);

for(map<int,vector<string> > ::iterator itI = Imap.begin();itI != Imap.end();itI++)
{
        int prodI,prodQ,sizeI,sizeQ;
        int posI = itI->second.at(0).find(".");
        int posQ = Qvec.at(0).find(".");
      /* If there is no decimal separation*/
        if(posI == -1) { prodI = atoi(itI->second.at(0).c_str());  sizeI =0;}
        if(posQ == -1) { prodQ = atoi(Qvec.at(0).c_str());  sizeQ =0;}
        /*If there is subdivision, then the string values are converetd to integer*/
        if(posI != -1)
        {
          prodI =  atoi(itI->second.at(0).substr(0,posI).c_str());
          int size1 = itI->second.at(0).size();
          sizeI = atoi(itI->second.at(0).substr(posI+1,size1).c_str());
        }
        if(posQ != -1)
        {
          prodQ =  atoi(Qvec.at(0).substr(0,posI).c_str());
          int size1 = Qvec.at(0).size();
          sizeQ = atoi(Qvec.at(0).substr(posI+1,size1).c_str());
        }
    string IProv,IReg,ICity;
        string QProv,QReg,QCity;
        int Ip,Ic,Ir;
        int Qp,Qc,Qr;
        int posPI = itI->second.at(1).find(".");
        int posPQ = Qvec.at(1).find(".");
        if( posPI == -1) {Ip = atoi(itI->second.at(1).c_str()); Ic = 0; Ir=0;}
        if( posPQ == -1) {Qp = atoi(Qvec.at(1).c_str()); Qc = 0; Qr=0;}
    if(posPI != -1)
        {
          Ip =  atoi(itI->second.at(1).substr(0,posPI).c_str());
          int sizePI = itI->second.at(1).size();
          ICity = itI->second.at(1).substr(posPI+1,sizePI);
          Ic = atoi(itI->second.at(1).substr(posPI+1,sizePI).c_str());
          int posPI1 = ICity.find(".");
          if(posPI1 == -1) { Ir = 0;}
          if(posPI1 != -1)
          {
             int sizePI2 = itI->second.at(1).substr(posPI+1,sizePI).size();
             Ic = atoi(ICity.substr(0,posPI1).c_str());
             Ir = atoi(ICity.substr(posPI+1,sizePI2).c_str());
           }
        }
        if(posPQ != -1)
        {
          Qp =  atoi(Qvec.at(1).substr(0,posPI).c_str());
          int sizePI = Qvec.at(1).size();
          QCity = Qvec.at(1).substr(posPI+1,sizePI);
          Qc = atoi(Qvec.at(1).substr(posPI+1,sizePI).c_str());
          int posPI1 = QCity.find(".");
          if(posPI1 == -1) { Qr = 0;}
          if(posPI1 != -1)
          {
             int sizePI2 = Qvec.at(1).substr(posPI+1,sizePI).size();
             Qc = atoi(QCity.substr(0,posPI1).c_str());
             Qr = atoi(QCity.substr(posPI+1,sizePI2).c_str());
           }
        }

    if( ((prodI == prodQ && sizeI == sizeQ) || ( prodI == prodQ && sizeQ == 0) ||(Qvec.at(0) == "-1")) &&( (prodI >=  0) && (prodI <= 10) && (sizeI >= 0) && ( sizeI <= 3)) )
        {
           /*Check for matching Province the city and the Division*/
           if(((Qp==Ip && Qc== Ic && Qr == Ir) || (Qp==Ip && Qc== Ic && Qr == 0) || (Qp==Ip && Qc== 0 && Qr == 0) || (Qvec.at(1) == "-1") ) &&( (Ip >= 0) && ( Ip <= 10) && (Ic >= 0) && (Ic <= 20 ) && (Ir >= 0 ) &&(Ir <= 5)) )
           {
              /*Check for matching gender*/
              if(itI->second.at(2) == Qvec.at(2))
              {
                 int range = Qvec.at(3).find("-");
                 int rng_siz = Qvec.at(3).size();
                 /*Condition to Check if the age in Queery is given as a range*/
                 if(range == -1)
                 {
                   int age = atoi(Qvec.at(3).substr(0,2).c_str());
                   if( atoi(itI->second.at(3).c_str()) == age && atoi(itI->second.at(3).c_str()) >=1 && atoi(itI->second.at(3).c_str()) <= 90)
                   {
                     /*Calculating the number of units sold totally for given Querry*/
                     if(atoi(itI->second.at(4).c_str()) <= 100) {result=result+atoi(itI->second.at(4).c_str());}
                   }
                 }
                 if (range != -1)
                 {
                    int age1 = atoi(Qvec.at(3).substr(0,range).c_str());
                    int age2 = atoi(Qvec.at(3).substr(range+1,rng_siz).c_str());
                    /*Checking for correct Age with the given age range*/
                    if( atoi(itI->second.at(3).c_str()) >= age1 && atoi(itI->second.at(3).c_str()) <= age2 && (atoi(itI->second.at(3).c_str())  >=  1) && (atoi(itI->second.at(3).c_str())  <= 90)  )
                    {
                      /*Calculating the number of units sold totally for given Querry*/
                      if(atoi(itI->second.at(4).c_str()) <= 100 ){ result=result+atoi(itI->second.at(4).c_str());}
                    }
                  }
              }
           }
        }
     }
 output.push_back(result);
    }
     Qvec.clear();
  }
 for(vector<int> :: iterator it= output.begin();it != output.end();it++)
 {
 cout << (*it) << endl;
 }

return 0;
}

Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>