NastySwipy

Arrays & Methods - 05. Pizza Ingredients

Apr 14th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. namespace _05b__Arrays_Exercises
  4. {
  5.     class Arrays_Exercises
  6.     {
  7.        static void Main(string[] args)
  8.         {
  9.             string[] ingredients = Console.ReadLine().Split(' ').ToArray();
  10.             int ingredientLength = int.Parse(Console.ReadLine());
  11.             string[] finalIngredients = new string[ingredients.Length];
  12.             int counter = 0;
  13.             for (int i = 0; i < ingredients.Length; i++)
  14.             {
  15.                 if (ingredients[i].Length == ingredientLength)
  16.                 {
  17.                     finalIngredients[i] += ingredients[i];
  18.                     Console.WriteLine($"Adding {ingredients[i]}.");
  19.                     counter++;
  20.                     if (counter >= 10)
  21.                     {
  22.                         break;
  23.                     }
  24.                 }
  25.             }
  26.             Console.WriteLine($"Made pizza with total of {counter} ingredients.\r\nThe ingredients are: {string.Join(", ", finalIngredients.Where(x => !string.IsNullOrEmpty(x)))}.");
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment