process involves adding toppings to individual pudding that have varying sizes that roll out on a conveyor belt.
- At least 1g of toppings needs to be added to each pudding.
- If two adjacent puddings are of different sizes, the larger piece needs to have at least 1g more than the smaller one.
- If two adjacent pieces are of the same size, then the amount of toppings relative to each other does not matter.
XXXXXXX
public class Program
{
static void Main(string[] args)
{
//topping t1 = new topping();
//t1.CalTopping();
topping t1 = new topping();
t1.CalTopping();
}
public class topping
{
public void CalTopping()
{
int[] cupcakes = { 1, 2, 2, 6, 2, 1 };
int tot = 0;
int topping = 0;
//int i=0;
for (int i = 0; i < cupcakes.Length; i++)
{
if (i + 1 < cupcakes.Length)
{
topping = 1;
if (cupcakes[i] == cupcakes[0])
{
topping = 1;
}
else if (cupcakes[i] > cupcakes[i - 1])
{
topping = topping + 1;
}
else
topping = 1;
}
tot = tot + topping;
Console.WriteLine(cupcakes[i] + " = " + topping + "g");
}
Console.WriteLine("total toppings Amount:-" + tot + "g");
}
}
}
}
i
is not an index. – gunr2171