Created
May 17, 2020 07:20
-
-
Save divyang4481/c8eb886c8fe403d0b1d5c0ad752b42d9 to your computer and use it in GitHub Desktop.
The Powerpuff Girls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.IO; | |
| using System.Linq; | |
| class CandidateCode { | |
| static void Main(String[] args) { | |
| //Write code here | |
| var ingredientCount = long.Parse(System.Console.ReadLine()); | |
| var ingredientFormula =System.Console.ReadLine().Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries); | |
| var ingredientStock = System.Console.ReadLine().Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries); | |
| var result =CaculateMaxPowerpuffGirls(ingredientCount, | |
| Array.ConvertAll(ingredientFormula, f => int.Parse(f.Trim())), | |
| Array.ConvertAll(ingredientStock, s => int.Parse(s.Trim()))); | |
| System.Console.WriteLine(result); | |
| } | |
| static int CaculateMaxPowerpuffGirls(long ingredientCount, int[] ingredientFormula, int[] ingredientStock ) | |
| { | |
| var count =0; | |
| var hasEnoughIngredeint=true; | |
| while(hasEnoughIngredeint) | |
| { | |
| for(int i=0 ; i<ingredientCount ;i++ ) | |
| { | |
| if(ingredientStock[i]>=ingredientFormula[i]) | |
| { | |
| ingredientStock[i] -=ingredientFormula[i]; | |
| } | |
| else | |
| { | |
| hasEnoughIngredeint=false; | |
| break; | |
| } | |
| } | |
| if(hasEnoughIngredeint) | |
| { | |
| count++; | |
| } | |
| else | |
| { | |
| break; | |
| } | |
| } | |
| return count; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment