1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
#include<iostream>
#include<string>
using namespace std;
void mcnuggets(int n,int *value1,int *value2);
void meal(int n,char a);
void single(int n,char a);
int main(){
//size_o = original size, size_m = size for meal, size_a = size for A la carte
int input[9],size_o[10],size_m[10],size_a[10],count(0),count2(0),c,f;
// o_letter = original letter, e_letter = extracted letter
char o_letter[10]={'a','A','b','c','d','e','f','g','h','i'},e_letter[10];
bool zero(1),stop(0);
fill_n(size_m,10,0);
string output;
cout<<"Welcome to McDonald's HK, what would you like to order?";
cout<<"(A)How many of Chicken McNuggets(s) you want to order(at least 4)? ";cin>>input[0];
cout<<"(B)How many set of McWings(s) you want to order? ";cin>>input[1];
cout<<"(C)How many of McSpicy Chicken Filet(s) you want to order? ";cin>>input[2];
cout<<"(D)How many of Sausage McMuffin with Egg(s) you want to order? ";cin>>input[3];
cout<<"(E)How many of Filet - O - Fish(s) you want to order? ";cin>>input[4];
cout<<"(F)How many of (small) Soft Drink(s) you want to order? ";cin>>input[5];
cout<<"(G)How many of (small) Fries(s) you want to order? ";cin>>input[6];
cout<<"(H)How many of Apple Pie(s) you want to order? ";cin>>input[7];
cout<<"(I)How many of Ice - cream(s) you want to order? ";cin>>input[8];
// check if order is placed
for(int i=0;i<=9;i++){
if(input[i]!=0) zero=0;
}
if(zero) cout<<"No order placed !"<<endl;
else{
if(input[0]==4 || (input[0]>=6 && (input[0]%3==0 || (input[0]-4)%3==0) ) ){
if((input[0]-4)%3==0) input[0]-=4;
if(input[0]!=4) mcnuggets(input[0],&size_o[0],&size_o[1]);
}
else {cout<<"No solution !"<<endl; stop=1;}
//to check if nuggets of 6 or 9 contains value and store the letter
if(!stop){
for(int i=0;i<=1;i++){
if(size_o[i]!=0){
e_letter[count]=o_letter[i];
count++;
}}
//extract the products which contains data
for(int i=1;i<=9;i++){
if(input[i]>0){
size_o[count]=input[i];
size_a[count]=size_o[count];
e_letter[count]=o_letter[i+1];
//if(i==5)c=count; if(i==6)f=count;
count++;
}}
//calculate size for meal
if(input[5]>=2 && input[6]>=2){
c=input[5];f=input[6];
for(int i=0;i<=count,c>=2 && f>=2;i++){
if(o_letter[i]!='f' && o_letter[i]!='g'&& o_letter[i]!='h'&& o_letter[i]!='i'){
size_m[i]=min(size_m[i],c/2,f/2);
size_a[i]-=size_m[i];
count2++;
c-=2;f-=2;
}
}
//output the plans
for(int i=0;i<=count;i++){
if(size_m[i]!=0){
meal(size_m[i],e_letter[i]);
if(i!=count)cout<<"+";}
}
for(int i=0;i<=count;i++){
if(size_a[i]!=0){
single(size_a[i],e_letter[i]);
if(i!=count)cout<<"+";}
}
}
}
}
return 0;
}
//functions
//calculate the combinations of mcnuggets
void mcnuggets(int n,int *value1,int *value2){
bool stop(0);
for(int i=0;i<=n/6;i++){
if (stop)break;
for(int x=0;x<=n/6;x++){ //n/6 is the largest posible no. of meals or A la carte
if(n-i*6-x*9==0){
*value1=i;
*value2=x;
stop=1;
break;
}
}
}
}
void meal(int n,char a){
switch(a){
case 'a':cout<<n<<" x M1 ($22.00)";break;
case 'A':cout<<n<<" x M2 ($35.50)";break;
case 'b':cout<<n<<" x M3 ($36.80)";break;
case 'c':cout<<n<<" x M4 ($22.00)";break;
case 'd':cout<<n<<" x M5 ($29.5)";break;
case 'e':cout<<n<<" x M6 ($33.00)";break;
}
}
void single(int n,char a){
switch(a){
case 'a':cout<<n<<" x A1 ($17.50)";break;
case 'A':cout<<n<<" x A2 ($35.50)";break;
case 'b':cout<<n<<" x A3 ($20.60)";break;
case 'c':cout<<n<<" x A4 ($20.50)";break;
case 'd':cout<<n<<" x A5 ($9.00)";break;
case 'e':cout<<n<<" x A6 ($10.00)";break;
case 'f':cout<<n<<" x V1 ($5.00)";break;
case 'g':cout<<n<<" x V2 ($5.00)";break;
case 'h':cout<<n<<" x V3 ($5.00)";break;
case 'i':cout<<n<<" x V4 ($5.00)";break;
}
}
|