Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Dishwasher
- {
- class Program
- {
- static void Main(string[] args)
- {
- int soupMl = int.Parse(Console.ReadLine()) * 750;
- int counter = 1;
- int dishes = 0;
- int pots = 0;
- string command = Console.ReadLine();
- while (command != "End")
- {
- int charging = int.Parse(command);
- if (counter % 3 != 0)
- {
- dishes += charging;
- soupMl -= charging * 5;
- }
- else
- {
- pots += charging;
- soupMl -= charging * 15;
- }
- if (soupMl < 0)
- {
- Console.WriteLine($"Not enough detergent, {Math.Abs(soupMl)} ml. more necessary!");
- break;
- }
- command = Console.ReadLine();
- counter++;
- }
- if (command == "End")
- {
- Console.WriteLine("Detergent was enough!");
- Console.WriteLine($"{dishes} dishes and {pots} pots were washed.");
- Console.WriteLine($"Leftover detergent {soupMl} ml.");
- }
- }
- }
- }
- РЕШЕНИЕ С FOR:
- using System;
- namespace Dishwasher
- {
- class Program
- {
- static void Main(string[] args)
- {
- int soupMl = int.Parse(Console.ReadLine()) * 750;
- int dishes = 0;
- int pots = 0;
- for (int i = 1; i < int.MaxValue; i++)
- {
- string command = Console.ReadLine();
- if (command == "End")
- {
- Console.WriteLine("Detergent was enough!");
- Console.WriteLine($"{dishes} dishes and {pots} pots were washed.");
- Console.WriteLine($"Leftover detergent {soupMl} ml.");
- break;
- }
- int charging = int.Parse(command);
- if (i % 3 != 0)
- {
- dishes += charging;
- soupMl -= charging * 5;
- }
- else
- {
- pots += charging;
- soupMl -= charging * 15;
- }
- if (soupMl < 0)
- {
- Console.WriteLine($"Not enough detergent, {Math.Abs(soupMl)} ml. more necessary!");
- break;
- }
- }
- }
- }
- }
- РЕШЕНИЕ С FOR И ТЕРНАРЕН ОПЕРАТОР:
- using System;
- namespace Dishwasher
- {
- class Program
- {
- static void Main(string[] args)
- {
- int soupMl = int.Parse(Console.ReadLine()) * 750;
- int dishes = 0;
- int pots = 0;
- string command = Console.ReadLine();
- for (int i = 1; i < int.MaxValue && command != "End" && soupMl >= 0; i++)
- {
- _ = i % 3 != 0 ? dishes += int.Parse(command) : pots += int.Parse(command);
- soupMl -= (i % 3 != 0 ? 5 : 15) * int.Parse(command);
- command = Console.ReadLine();
- }
- Console.WriteLine(soupMl < 0 ? $"Not enough detergent, {Math.Abs(soupMl)} ml. more necessary!"
- : $"Detergent was enough!\n{dishes} dishes and {pots} pots were washed.\nLeftover detergent {soupMl} ml.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement