Thread: complex problem and efforts

  1. #1
    Registered User
    Join Date
    Jan 2020
    Posts
    20

    complex problem and efforts

    Hi,

    How to write program for below problem:-

    Chef's ingredients:-




    1.The chef receives exactly 1 ingredient per day from the market.The
    ingredients never repeat.


    2. Every ingredient belongs to 1 of the 3 categories namely FIBER,FAT & CARB.


    3.Every ingredient has a unique ingredient id.


    4.The ingredient id always starts with the category name (ex:FIBERBroccoli,FATCheese,CARBRice)


    Chef's Dishes


    1. All of the chef's dishes have a constant number of ingredients.(this will be your program's input)


    2. All the ingredients used will be fully used in a Dish. The chef doesn' use some part/quntity of an ingredient.


    3.All of the chef's dishes mush have at least 60% of the ingredients from a single category.(i.e. if the chef cooks using
    4 ingredients,then at leaast 3 FAT ingredients OR at least 3 FIBER ingredients OR at least 3 CARB ingredients are needed)




    Chef's Cooking style:-


    1. If the chef has multiple options of ingredients for the dish,then he takes the oldest possible ones to cook
    in the order of their arrival.


    2.After the chef prepares a dish,the ingredients used can Not be reused as theyhave been already used.


    3.The chef prepares a maximum of 1 dish per day.


    4.if the Chef does not have enough ingredients to cook the dish with above mentioned rules,then he does not
    cook on that day.


    Given the input array of ingredient id that the chef receives every day (i.e. array index is the day number)
    write a program to print when does the chef cook a dish and when he does not.




    Input:-


    Line 1: The total number of days for the scope of the problem(1<=input<=20)


    Line 2: The exact number of ingredients that chef uses to cook(1<=input<=20)


    Line 3: The space separated ingredient ids.(6<=length(ingredientid)<=20)


    Output:- Print the ":" separated used ingredient ids in order of their arrival if the chef cooks on that day
    and print "-" if the chef doesn't cook anything on that day.Print the output as single string.


    Example input 1:


    5
    3
    FATOil FATCheese FATEgg FIBERSpinach CARBRice FIBERBeans


    Example INPUT 2:


    6
    3
    FATOil:FATCheese FATEgg FIBERSpinach CARBRice FIBERBeans


    EXAMPLE OUTPUT 2:


    --FATOil:FATCheese:FATEgg--FIBERSpinach:CARBRice:FIBERBeans


    EXAMPLE INPUT 3:
    I am not sure I am interpreting this correctly. What I am reading is the following:

    a. Your program is going to prompt for input 3 times

    • Input 1: Specify the number of days the chef will be going to market
    • Input 2: Specify how many ingredients the chef will need for a dish
    • Input 3: A list of the ingredients, one for each day, in format CATEGORY-IngredientName, separated by a space

    b. Rules for the input:

    • Ingredient names may not repeat
    • Chef will only pick up one ingredient per day (hence number of entries on input #3 must match what you added in input #1)
    • At least 60% of dishes must be from the same category

    c. Output

    • For each day, print what ingredients a dish will have per day. However, if there are not enough ingredients to satisfy the dish, mark the day with a



    If you look at example #1 given:

    Example input 1:

    5
    3
    FATOil FATCheese FATEgg FIBERSpinach CARBRice FIBERBeans


    for 1st case output should be like :- ---FATOil:FIBERSpinach:FATCheese-

    So here, the Chef will go 5 time to the market, he will need 3 ingredients for a dish. The 5 ingredients listed are FATOil FATCheese FATEgg FIBERSpinach CARBRice (FIBERBeans would not be picked up if the input was 5 days).

    • For the first day, no dish, output is
    • For the 2nd day, no dish, output is
    • For the 3rd day, no dish, as all 3 items up to day 3 were from the same category (not sure if this is supposed to be a rule)
    • For the 4th day, the output for the dish will be FATOil, FATCHEESE and FIBERSpinach
    • For the 5th day, no dish as there are no ingredients available to satisfy the 3-ingredient requirement


    Program flow, I am a bit hazy on this, but suggest something like this


    1. Take input, and check if it matches the input criteria (1<=input<=20)
    2. Once you received input from all three lines, do the following, for each day (as specified on input 1)
      • Loop number of days

    i. Check if the ingredients match the rules. You will have to check your rules one-by-one for this
    ii. If all the rules have passed, you can print it for the day
    iii. If the rules have failed, print a dash

    • Loop again


    12
    4
    FATOil FIBERSpinach CARBRice FATCheese FIBERBeans FATEgg
    FIBERBroccoil CARBPotato CARBCorn FATOlive FIBERCarrot

    ************************************************** *************

    solution:-

    this is with respect to
    complex problem




    a. this program is going to prompt for input 3 times

    • Input 1: Specify the number of days the chef will be going to market
    • Input 2: Specify how many ingredients the chef will need for a dish
    • Input 3: A list of the ingredients, one for each day, in format CATEGORY-IngredientName, separated by a space

    b. Rules for the input:

    • Ingredient names may not repeat
    • Chef will only pick up one ingredient per day (hence number of entries on input #3 must match what you added in input #1)
    • At least 60% of dishes must be from the same category

    c. Output

    • For each day, print what ingredients a dish will have per day. However, if there are not enough ingredients to satisfy the dish, mark the day with a



    If you look at example #1 given:

    Example input 1:

    5
    3
    FATOil FATCheese FATEgg FIBERSpinach CARBRice FIBERBeans


    for 1st case output should be like :- ---FATOil:FIBERSpinach:FATCheese-

    So here, the Chef will go 5 time to the market, he will need 3 ingredients for a dish. The 5 ingredients listed are FATOil FATCheese FATEgg FIBERSpinach CARBRice (FIBERBeans would not be picked up if the input was 5 days).

    • For the first day, no dish, output is
    • For the 2nd day, no dish, output is
    • For the 3rd day, no dish, as all 3 items up to day 3 were from the same category (not sure if this is supposed to be a rule)
    • For the 4th day, the output for the dish will be FATOil, FATCHEESE and FIBERSpinach
    • For the 5th day, no dish as there are no ingredients available to satisfy the 3-ingredient requirement


    Program flow, I am a bit hazy on this, but suggest something like this


    1. Take input, and check if it matches the input criteria (1<=input<=20)
    2. Once you received input from all three lines, do the following, for each day (as specified on input 1)
      • Loop number of days

    i. Check if the ingredients match the rules. You will have to check your rules one-by-one for this
    ii. If all the rules have passed, you can print it for the day
    iii. If the rules have failed, print a dash

    • Loop again



  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    3,771
    And where is the code that shows you tried to work on this problem!

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. complex problem
    By bintech21 in forum C++ Programming
    Replies: 1
    Last Post: 02-04-2020, 11:52 PM
  2. Another more complex problem,
    By Tynnhammar in forum C++ Programming
    Replies: 9
    Last Post: 09-29-2004, 11:35 PM
  3. I've exhausted all efforts...
    By Hillbillie in forum C Programming
    Replies: 5
    Last Post: 11-16-2002, 11:57 AM

Tags for this Thread