Monday, December 7, 2020

Code Gladiators 2020 - The Powerpuff Girls Coding Problem in C#

Professor Utonium is restless because of the increasing crime in the world. The number of villains and their activities has increased to a great extent. The current trio of Powerpuff Girls is not well to fight the evils of the whole world. Professor has decided to create the maximum number of Powerpuff Girls with the ingredients he has.

There are N ingredients required in a certain quantity to create a Powerpuff Girl. Professor has all the N ingredients in his laboratory and knows the quantity of each available ingredient. He also knows the quantity of a particular ingredient required to create a Powerpuff Girl. Professor is busy with the preparations and wants to start asap.

The villains, on the other hand, want to destroy the laboratory and stop Professor Utonium from creating more Powerpuff girls. Mojo Jojo is coming prepared with ammunition and Him is leading other villains like Princess, Amoeba Boys, Sedusa, Gangreen Gang etc.

Professor does not have much time as villains will reach the laboratory soon. He is starting the process but does not know the number of Powerpuff Girls which will be created. He needs your help in determining the maximum number of Powerpuff Girls which will be created with the current quantity of ingredients.

Example:
Professor Utonium requires 3 ingredients to make Powerpuff Girls. The 3 ingredients are present in the laboratory in the given quantity:


To make a Powerpuff Girl, Professor Utonium requires:
3 units of Ingredient A
6 units of Ingredient B
10 units of Ingredient C
The maximum number of Powerpuff Girls that can be created is 3 as, after 3, Professor will run out of Ingredient C.


Can you determine the maximum number?

Input Format
The first line of input consists of the number of ingredients, N
The second line of input consists of the N space-separated integers representing the quantity of each ingredient required to create a Powerpuff Girl.
The third line of input consists of the N space-separated integers representing the quantity of each ingredient present in the laboratory.

Constraints:
1<= N <=10000000 (1e7)
0<= Quantity_of_ingredient <= LLONG_MAX 
Output Format
Print the required output in a separate line.

Sample TestCase
Input
4
2 5 6 3 
20 40 90 50 
Output
8

Solution :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    public class PowerpuffGirls
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("PowerpuffGirls Problem");
            bool flag = false;
            long count = 0;
            long N = Convert.ToInt64(Console.ReadLine());
            string StrReqQuantity = Console.ReadLine();
            StrReqQuantity = StrReqQuantity.Trim();
            string StrAvailableQuantity = Console.ReadLine();
            StrAvailableQuantity = StrAvailableQuantity.Trim();

            string[] StrReqQuantityArray = StrReqQuantity.Split(' ');
            string[] StrAvailableQuantityArray = StrAvailableQuantity.Split(' ');

            long[] RequiredQuantityArray = Array.ConvertAll(StrReqQuantityArray, q => long.Parse(q));
            long[] AvailableQuantityArray = Array.ConvertAll(StrAvailableQuantityArray, a => long.Parse(a));

            long[] ReverseAvailableQuantityArray = new long[N];
            ReverseAvailableQuantityArray = Array.ConvertAll(StrAvailableQuantityArray, a => long.Parse(a));
            Array.Sort(ReverseAvailableQuantityArray);
            long LargestElment = ReverseAvailableQuantityArray[N - 1];


            for (long i = 0; i < LargestElment; i++)
            {
                for (long j = 0; j < N; j++)
                {
                    if (RequiredQuantityArray[j] <= AvailableQuantityArray[j])
                    {
                        flag = true;
                        AvailableQuantityArray[j] = AvailableQuantityArray[j] - RequiredQuantityArray[j];
                    }
                    else
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag == true)
                {
                    count = count + 1;
                }
                if (flag == false)
                {
                    break;
                }
            }
            Console.WriteLine(count);
            Console.Read();

        }
    }
}

Saturday, December 5, 2020

Right Angled Alphabet Triangle in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class PrintABCDE
    {
        static void Main()
        {
            string Stroutput = string.Empty;
            Console.WriteLine("Enter any number between 1 and 26");
            int UserNumber = int.Parse(Console.ReadLine());
            if (UserNumber >= 1 && UserNumber <= 26)
            {
                char[] alpha = Enumerable.Range('A', UserNumber).Select(i => (Char)i).ToArray();
                for (int i = 0; i < UserNumber; i++)
                {
                    for (int y = 0; y <= i; y++)
                    {
                        Stroutput = string.Format(Stroutput + alpha[y] + " ");
                    }
                    Stroutput = Stroutput.Remove(Stroutput.Length - 1);
                    if (i == UserNumber - 1)
                    {
                        Console.Write(Stroutput);
                        Stroutput = string.Empty;
                    }
                    else
                    {
                        Console.WriteLine(Stroutput);
                        Stroutput = string.Empty;
                    }
                }
            }
            else
            {
                Console.WriteLine("Number entered is not in Given Range");
            }
            Console.Read();
        }
    }
}

Output 1 :

Output 2 :