Advertisement
Guest User

Pizza Ingredients

a guest
Jun 10th, 2017
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _05.Pizza_Ingredients
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             var allIngredients = Console.ReadLine().Split(' ');
  10.             var stringLenght = long.Parse(Console.ReadLine());
  11.  
  12.             var ingredientsCount = 0;
  13.  
  14.             var pizzaIngredients = new string[allIngredients.Length];
  15.  
  16.             foreach (var ingredient in allIngredients)
  17.             {
  18.                 if (ingredient.Length == stringLenght)
  19.                 {
  20.                     pizzaIngredients[ingredientsCount] = ingredient;
  21.                     ingredientsCount++;
  22.                     Console.WriteLine($"Adding {ingredient}.");
  23.  
  24.                     if (ingredientsCount == 9)
  25.                     {
  26.                         break;
  27.                     }
  28.                 }
  29.             }
  30.  
  31.             Console.WriteLine($"Made pizza with total of {ingredientsCount} ingredients.");
  32.             Console.Write("The ingredients are: ");
  33.  
  34.             for (int i = 0; i < pizzaIngredients.Length; i++)
  35.             {
  36.                 if (ingredientsCount > 1)
  37.                 {
  38.                     Console.Write(pizzaIngredients[i] + ", ");
  39.                     ingredientsCount--;
  40.                 }
  41.                 else if (ingredientsCount == 1)
  42.                 {
  43.                     Console.Write(pizzaIngredients[i] + ".");
  44.                     break;
  45.                 }
  46.             }
  47.             Console.WriteLine();
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement