SlideShare a Scribd company logo
1 of 3
#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

What's hot (20)

Factorial
FactorialFactorial
Factorial
 
week-21x
week-21xweek-21x
week-21x
 
Session06 functions
Session06 functionsSession06 functions
Session06 functions
 
One dimensional operation of Array in C- language
One dimensional operation of Array in C- language One dimensional operation of Array in C- language
One dimensional operation of Array in C- language
 
Infix to-postfix examples
Infix to-postfix examplesInfix to-postfix examples
Infix to-postfix examples
 
cosc 281 hw2
cosc 281 hw2cosc 281 hw2
cosc 281 hw2
 
C++ question 6 || solution of Programming Problem
C++ question 6 || solution of Programming Problem C++ question 6 || solution of Programming Problem
C++ question 6 || solution of Programming Problem
 
Circular queues
Circular queuesCircular queues
Circular queues
 
STL
STLSTL
STL
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Operators and expression in c#
Operators and expression in c#Operators and expression in c#
Operators and expression in c#
 
C++ Programming - 3rd Study
C++ Programming - 3rd StudyC++ Programming - 3rd Study
C++ Programming - 3rd Study
 
Ooprc3c
Ooprc3cOoprc3c
Ooprc3c
 
Circular queue
Circular queueCircular queue
Circular queue
 
XKE Typeclass
XKE TypeclassXKE Typeclass
XKE Typeclass
 
Ayam potong
Ayam potongAyam potong
Ayam potong
 
basic shell_programs
 basic shell_programs basic shell_programs
basic shell_programs
 
API .Net + MongoDB
API .Net + MongoDBAPI .Net + MongoDB
API .Net + MongoDB
 
Data type a la carte
Data type a la carteData type a la carte
Data type a la carte
 
Ruby haskell extension
Ruby haskell extensionRuby haskell extension
Ruby haskell extension
 

Viewers also liked

Вопросы иммуногенности и безопасности биологической терапии
Вопросы иммуногенности и безопасности биологической терапииВопросы иммуногенности и безопасности биологической терапии
Вопросы иммуногенности и безопасности биологической терапииИрина Головач
 
Triangle 2016 - Boosting it ecosystems with zero budgets role and impact of i...
Triangle 2016 - Boosting it ecosystems with zero budgets role and impact of i...Triangle 2016 - Boosting it ecosystems with zero budgets role and impact of i...
Triangle 2016 - Boosting it ecosystems with zero budgets role and impact of i...Viacheslav Maiakin
 
Capacity building via OpenCoesione, the Italian open strategy on cohesion po...
Capacity building via OpenCoesione, the Italian open strategy on cohesion po...Capacity building via OpenCoesione, the Italian open strategy on cohesion po...
Capacity building via OpenCoesione, the Italian open strategy on cohesion po...carloamati
 
政治的無関心の構造:人は「政治」の何を見ているのか?
政治的無関心の構造:人は「政治」の何を見ているのか?政治的無関心の構造:人は「政治」の何を見ているのか?
政治的無関心の構造:人は「政治」の何を見ているのか?Masaki Hata
 
Benefits Of Virtual Private Cloud
Benefits Of Virtual Private CloudBenefits Of Virtual Private Cloud
Benefits Of Virtual Private Cloudmatthummels
 
The 5 Fundamentals of Content Marketing
The 5 Fundamentals of Content MarketingThe 5 Fundamentals of Content Marketing
The 5 Fundamentals of Content MarketingInfluence & Co.
 

Viewers also liked (10)

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

Similar to New text document

CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical filePranav Ghildiyal
 
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...Mateusz Zalewski
 
12.9 Program Online shopping cart (continued) (C++)This program e.pdf
12.9 Program Online shopping cart (continued) (C++)This program e.pdf12.9 Program Online shopping cart (continued) (C++)This program e.pdf
12.9 Program Online shopping cart (continued) (C++)This program e.pdffasttracksunglass
 
#include stdio.h#include stdint.h#include stdbool.h.docx
#include stdio.h#include stdint.h#include stdbool.h.docx#include stdio.h#include stdint.h#include stdbool.h.docx
#include stdio.h#include stdint.h#include stdbool.h.docxAASTHA76
 
"Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze...
"Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze..."Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze...
"Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze...Mateusz Zalewski
 
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdfC++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdfinfo189835
 
Header file for an array-based implementation of the ADT bag. @f.pdf
 Header file for an array-based implementation of the ADT bag. @f.pdf Header file for an array-based implementation of the ADT bag. @f.pdf
Header file for an array-based implementation of the ADT bag. @f.pdfsudhirchourasia86
 
I keep getting an error about m_pHead in printStoresInfo(); function.pdf
I keep getting an error about m_pHead in printStoresInfo(); function.pdfI keep getting an error about m_pHead in printStoresInfo(); function.pdf
I keep getting an error about m_pHead in printStoresInfo(); function.pdfflashfashioncasualwe
 
So I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdfSo I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdfarjuncollection
 
Calculator code with scientific functions in java
Calculator code with scientific functions in java Calculator code with scientific functions in java
Calculator code with scientific functions in java Amna Nawazish
 
#include stdafx.h#include iostreamusing namespace std;cl.pdf
#include stdafx.h#include iostreamusing namespace std;cl.pdf#include stdafx.h#include iostreamusing namespace std;cl.pdf
#include stdafx.h#include iostreamusing namespace std;cl.pdfaashwini4
 
I keep on get a redefinition error and an undefined error.Customer.pdf
I keep on get a redefinition error and an undefined error.Customer.pdfI keep on get a redefinition error and an undefined error.Customer.pdf
I keep on get a redefinition error and an undefined error.Customer.pdfherminaherman
 
basic programs in C++
basic programs in C++ basic programs in C++
basic programs in C++ Arun Nair
 
Getting error - (Return type of out-of-line definition of 'Product--Ge.pdf
Getting error - (Return type of out-of-line definition of 'Product--Ge.pdfGetting error - (Return type of out-of-line definition of 'Product--Ge.pdf
Getting error - (Return type of out-of-line definition of 'Product--Ge.pdfNicholasflqStewartl
 
OO JS for AS3 Devs
OO JS for AS3 DevsOO JS for AS3 Devs
OO JS for AS3 DevsJason Hanson
 

Similar to New text document (17)

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