SlideShare a Scribd company logo
#include<stdio.h>
#include<string.h>
#define MAX 100
#define COST_AT_ARGENTINA 50
#define COST_AT_BRAZIL 100
#define COST_OF_TRANSPORTATION 400
#define MAX_ITEM_CAN_IMPORTED 10
int inputValidator(const char* countryName)
{
if(strcmp(countryName,"ARGENTINA")==0||strcmp(countryName,"argentina")==0||
strcmp(countryName,"BRAZIL")==0||strcmp(countryName,"brazil")==0)
return 1;
return 0;
}
//function to find cost if order placed in argentina//
int findCostAtArgentina(int numberOfItemOrdered,int*
itemLeftInArgentinaStock,int* itemLeftInBrazilStock)
{
int
numberOfItemImported,numberOfItemUnImported,totalCost=0,numberOfItemCantImport;
int numberOfBlockImported;
if(numberOfItemOrdered>MAX)
{
numberOfItemImported=numberOfItemOrdered%MAX;
if((numberOfItemImported%MAX_ITEM_CAN_IMPORTED)!=0)
{
fprintf(stderr,"CANNOT COMPLETE THE ORDER MAY BE DUE TO 'OUT OF
STOCK'n");
return 0;
}
numberOfBlockImported=numberOfItemImported/MAX_ITEM_CAN_IMPORTED;
totalCost=(MAX*COST_AT_ARGENTINA)+
(numberOfBlockImported*COST_OF_TRANSPORTATION)+
(numberOfItemImported*COST_AT_BRAZIL);
*itemLeftInArgentinaStock=0;
*itemLeftInBrazilStock-=numberOfItemImported;
//printf("total_Cost=%d",totalCost);
}
else
{
totalCost=(numberOfItemOrdered*COST_AT_ARGENTINA);
*itemLeftInArgentinaStock-=numberOfItemOrdered;
}
return totalCost;
}
//function to find cost if order placed in Brazil//
int findCostAtBrazil(int numberOfItemOrdered,int* itemLeftInArgentinaStock,int*
itemLeftInBrazilStock)
{
int
numberOfItemImported,numberOfItemUnImported,totalCost=0,numberOfItemCantImport;
int numberOfBlockImported;
int brazilTempCost=0,argentinaTempCost=0;
if(numberOfItemOrdered>MAX)
{
brazilTempCost+=MAX*COST_AT_ARGENTINA;
brazilTempCost+=((MAX/MAX_ITEM_CAN_IMPORTED)*COST_OF_TRANSPORTATION);
numberOfItemOrdered-=MAX;
brazilTempCost+=(numberOfItemOrdered*COST_AT_BRAZIL);
*itemLeftInArgentinaStock-=MAX;
*itemLeftInBrazilStock-=numberOfItemOrdered;
return brazilTempCost;
}
else
{
brazilTempCost+=numberOfItemOrdered*COST_AT_BRAZIL;
numberOfBlockImported=numberOfItemOrdered/MAX_ITEM_CAN_IMPORTED;
numberOfItemCantImport=numberOfItemOrdered%MAX_ITEM_CAN_IMPORTED;
argentinaTempCost+=(numberOfBlockImported)*COST_OF_TRANSPORTATION;
argentinaTempCost+=(numberOfBlockImported*10*COST_AT_ARGENTINA);
argentinaTempCost+=numberOfItemCantImport*COST_AT_BRAZIL;
*itemLeftInArgentinaStock-=(numberOfBlockImported*10);
*itemLeftInBrazilStock-=numberOfItemCantImport;
if(brazilTempCost>argentinaTempCost)
totalCost=brazilTempCost;
else
totalCost=argentinaTempCost;
return totalCost;
}
}
void solveForEachOrder()
{
char countryName[20]="";
int numberOfItemOrdered;
int itemLeftInBrazilStock,itemLeftInArgentinaStock;
int sellingCostAtArgentina,sellingCostAtBrazil;
itemLeftInArgentinaStock=itemLeftInBrazilStock=MAX; // Reinitalize the Stock
to 100
scanf("%s %d",countryName,&numberOfItemOrdered);
if(numberOfItemOrdered>200)
{
fprintf(stderr,"ORDER RANGE MUST BE IN BETWEEN 0 to 200n");
return 0;
}
if(inputValidator(countryName))
{
printf("%sn",countryName);
if(strcmp(countryName,"argentina")==0||
strcmp(countryName,"ARGENTINA")==0)
{
sellingCostAtArgentina=findCostAtArgentina(numberOfItemOrdered,&itemLeftInArgent
inaStock,&itemLeftInBrazilStock);
printf("Argentina %d:%d:
%dn",sellingCostAtArgentina,itemLeftInBrazilStock,itemLeftInArgentinaStock);
}
else
{
sellingCostAtBrazil=findCostAtBrazil(numberOfItemOrdered,&itemLeftInArgentinaSto
ck,&itemLeftInBrazilStock);
printf("Brazil %d:%d:
%dn",sellingCostAtBrazil,itemLeftInBrazilStock,itemLeftInArgentinaStock);
}
}
else
fprintf(stderr,"NOT A VALID COUNTRY NAMEn");
}
int main()
{
freopen("inp.txt","r",stdin);
int numberOfTotalOrdersToBePlaced; //variable for different test cases
printf("ENTER NO. OF TOTAL NUMBER OF ORDER YOU WANT TO PLACEn");
scanf("%d",&numberOfTotalOrdersToBePlaced);
while(numberOfTotalOrdersToBePlaced-->0)
{
solveForEachOrder();
}
return 0;
}

More Related Content

DOCX
Code sources des fonctions table cp
DOCX
PROGRAM FOR INSERTION SORTING IN ARRAY
PPTX
Computer programing w
PDF
DOCX
Document
DOCX
Class array
TXT
Program to sort array using insertion sort
Code sources des fonctions table cp
PROGRAM FOR INSERTION SORTING IN ARRAY
Computer programing w
Document
Class array
Program to sort array using insertion sort

What's hot (20)

PDF
Factorial
PPTX
Session06 functions
DOCX
One dimensional operation of Array in C- language
DOC
Infix to-postfix examples
DOCX
cosc 281 hw2
PDF
C++ question 6 || solution of Programming Problem
PPT
Circular queues
PDF
Insertion sort
PPTX
Operators and expression in c#
PDF
C++ Programming - 3rd Study
PDF
Ooprc3c
DOCX
Circular queue
PDF
XKE Typeclass
TXT
Ayam potong
DOC
basic shell_programs
PDF
API .Net + MongoDB
PDF
Data type a la carte
KEY
Ruby haskell extension
Factorial
Session06 functions
One dimensional operation of Array in C- language
Infix to-postfix examples
cosc 281 hw2
C++ question 6 || solution of Programming Problem
Circular queues
Insertion sort
Operators and expression in c#
C++ Programming - 3rd Study
Ooprc3c
Circular queue
XKE Typeclass
Ayam potong
basic shell_programs
API .Net + MongoDB
Data type a la carte
Ruby haskell extension
Ad

Viewers also liked (10)

PPTX
Вопросы иммуногенности и безопасности биологической терапии
DOCX
PDF
publi_mP_Ottakringer_Buch_2015
PDF
Energi&Bolig_Vol4_web
PPTX
Triangle 2016 - Boosting it ecosystems with zero budgets role and impact of i...
PPTX
Capacity building via OpenCoesione, the Italian open strategy on cohesion po...
PPTX
政治的無関心の構造:人は「政治」の何を見ているのか?
PPTX
Benefits Of Virtual Private Cloud
PDF
Blur Watering Hole
PPTX
The 5 Fundamentals of Content Marketing
Вопросы иммуногенности и безопасности биологической терапии
publi_mP_Ottakringer_Buch_2015
Energi&Bolig_Vol4_web
Triangle 2016 - Boosting it ecosystems with zero budgets role and impact of i...
Capacity building via OpenCoesione, the Italian open strategy on cohesion po...
政治的無関心の構造:人は「政治」の何を見ているのか?
Benefits Of Virtual Private Cloud
Blur Watering Hole
The 5 Fundamentals of Content Marketing
Ad

Similar to New text document (18)

DOC
CBSE Class XII Comp sc practical file
PDF
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...
PDF
12.9 Program Online shopping cart (continued) (C++)This program e.pdf
DOCX
#include stdio.h#include stdint.h#include stdbool.h.docx
PDF
"Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze...
PDF
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
PDF
Header file for an array-based implementation of the ADT bag. @f.pdf
PDF
I keep getting an error about m_pHead in printStoresInfo(); function.pdf
PDF
So I already have most of the code and now I have to1. create an .pdf
DOCX
Add invoice
DOCX
Calculator code with scientific functions in java
PDF
#include stdafx.h#include iostreamusing namespace std;cl.pdf
PDF
I keep on get a redefinition error and an undefined error.Customer.pdf
PDF
Quiniela
PDF
C++ normal assignments by maharshi_jd.pdf
DOCX
basic programs in C++
PDF
Getting error - (Return type of out-of-line definition of 'Product--Ge.pdf
PPT
OO JS for AS3 Devs
CBSE Class XII Comp sc practical file
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...
12.9 Program Online shopping cart (continued) (C++)This program e.pdf
#include stdio.h#include stdint.h#include stdbool.h.docx
"Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze...
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
Header file for an array-based implementation of the ADT bag. @f.pdf
I keep getting an error about m_pHead in printStoresInfo(); function.pdf
So I already have most of the code and now I have to1. create an .pdf
Add invoice
Calculator code with scientific functions in java
#include stdafx.h#include iostreamusing namespace std;cl.pdf
I keep on get a redefinition error and an undefined error.Customer.pdf
Quiniela
C++ normal assignments by maharshi_jd.pdf
basic programs in C++
Getting error - (Return type of out-of-line definition of 'Product--Ge.pdf
OO JS for AS3 Devs

New text document

  • 1. #include<stdio.h> #include<string.h> #define MAX 100 #define COST_AT_ARGENTINA 50 #define COST_AT_BRAZIL 100 #define COST_OF_TRANSPORTATION 400 #define MAX_ITEM_CAN_IMPORTED 10 int inputValidator(const char* countryName) { if(strcmp(countryName,"ARGENTINA")==0||strcmp(countryName,"argentina")==0|| strcmp(countryName,"BRAZIL")==0||strcmp(countryName,"brazil")==0) return 1; return 0; } //function to find cost if order placed in argentina// int findCostAtArgentina(int numberOfItemOrdered,int* itemLeftInArgentinaStock,int* itemLeftInBrazilStock) { int numberOfItemImported,numberOfItemUnImported,totalCost=0,numberOfItemCantImport; int numberOfBlockImported; if(numberOfItemOrdered>MAX) { numberOfItemImported=numberOfItemOrdered%MAX; if((numberOfItemImported%MAX_ITEM_CAN_IMPORTED)!=0) { fprintf(stderr,"CANNOT COMPLETE THE ORDER MAY BE DUE TO 'OUT OF STOCK'n"); return 0; } numberOfBlockImported=numberOfItemImported/MAX_ITEM_CAN_IMPORTED; totalCost=(MAX*COST_AT_ARGENTINA)+ (numberOfBlockImported*COST_OF_TRANSPORTATION)+ (numberOfItemImported*COST_AT_BRAZIL); *itemLeftInArgentinaStock=0; *itemLeftInBrazilStock-=numberOfItemImported; //printf("total_Cost=%d",totalCost); } else { totalCost=(numberOfItemOrdered*COST_AT_ARGENTINA); *itemLeftInArgentinaStock-=numberOfItemOrdered; } return totalCost; } //function to find cost if order placed in Brazil// int findCostAtBrazil(int numberOfItemOrdered,int* itemLeftInArgentinaStock,int* itemLeftInBrazilStock) { int numberOfItemImported,numberOfItemUnImported,totalCost=0,numberOfItemCantImport; int numberOfBlockImported; int brazilTempCost=0,argentinaTempCost=0; if(numberOfItemOrdered>MAX) { brazilTempCost+=MAX*COST_AT_ARGENTINA; brazilTempCost+=((MAX/MAX_ITEM_CAN_IMPORTED)*COST_OF_TRANSPORTATION); numberOfItemOrdered-=MAX; brazilTempCost+=(numberOfItemOrdered*COST_AT_BRAZIL); *itemLeftInArgentinaStock-=MAX; *itemLeftInBrazilStock-=numberOfItemOrdered; return brazilTempCost;
  • 2. } else { brazilTempCost+=numberOfItemOrdered*COST_AT_BRAZIL; numberOfBlockImported=numberOfItemOrdered/MAX_ITEM_CAN_IMPORTED; numberOfItemCantImport=numberOfItemOrdered%MAX_ITEM_CAN_IMPORTED; argentinaTempCost+=(numberOfBlockImported)*COST_OF_TRANSPORTATION; argentinaTempCost+=(numberOfBlockImported*10*COST_AT_ARGENTINA); argentinaTempCost+=numberOfItemCantImport*COST_AT_BRAZIL; *itemLeftInArgentinaStock-=(numberOfBlockImported*10); *itemLeftInBrazilStock-=numberOfItemCantImport; if(brazilTempCost>argentinaTempCost) totalCost=brazilTempCost; else totalCost=argentinaTempCost; return totalCost; } } void solveForEachOrder() { char countryName[20]=""; int numberOfItemOrdered; int itemLeftInBrazilStock,itemLeftInArgentinaStock; int sellingCostAtArgentina,sellingCostAtBrazil; itemLeftInArgentinaStock=itemLeftInBrazilStock=MAX; // Reinitalize the Stock to 100 scanf("%s %d",countryName,&numberOfItemOrdered); if(numberOfItemOrdered>200) { fprintf(stderr,"ORDER RANGE MUST BE IN BETWEEN 0 to 200n"); return 0; } if(inputValidator(countryName)) { printf("%sn",countryName); if(strcmp(countryName,"argentina")==0|| strcmp(countryName,"ARGENTINA")==0) { sellingCostAtArgentina=findCostAtArgentina(numberOfItemOrdered,&itemLeftInArgent inaStock,&itemLeftInBrazilStock); printf("Argentina %d:%d: %dn",sellingCostAtArgentina,itemLeftInBrazilStock,itemLeftInArgentinaStock); } else { sellingCostAtBrazil=findCostAtBrazil(numberOfItemOrdered,&itemLeftInArgentinaSto ck,&itemLeftInBrazilStock); printf("Brazil %d:%d: %dn",sellingCostAtBrazil,itemLeftInBrazilStock,itemLeftInArgentinaStock); } } else fprintf(stderr,"NOT A VALID COUNTRY NAMEn"); } int main() {
  • 3. freopen("inp.txt","r",stdin); int numberOfTotalOrdersToBePlaced; //variable for different test cases printf("ENTER NO. OF TOTAL NUMBER OF ORDER YOU WANT TO PLACEn"); scanf("%d",&numberOfTotalOrdersToBePlaced); while(numberOfTotalOrdersToBePlaced-->0) { solveForEachOrder(); } return 0; }