Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace SuitcasesLoad
- {
- class Program
- {
- static void Main()
- {
- double size = double.Parse(Console.ReadLine());
- string suitcase = Console.ReadLine();
- int counter = 0;
- while (suitcase != "End")
- {
- counter++;
- double box = double.Parse(suitcase);
- if (counter % 3 == 0)
- {
- box *= 1.1;
- }
- if (box > size)
- {
- counter--;
- break;
- }
- size -= box;
- suitcase = Console.ReadLine();
- }
- if (suitcase == "End")
- {
- Console.WriteLine("Congratulations! All suitcases are loaded!");
- }
- else
- {
- Console.WriteLine("No more space!");
- }
- Console.WriteLine($"Statistic: {counter} suitcases loaded.");
- }
- }
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- using System;
- namespace SuitcasesLoad
- {
- class Program
- {
- static void Main()
- {
- double size = double.Parse(Console.ReadLine());
- int counter = 0;
- while (size >= 0)
- {
- string suitcase = Console.ReadLine();
- if (suitcase == "End")
- {
- break;
- }
- counter++;
- double box = double.Parse(suitcase);
- box *= counter % 3 == 0 ? 1.1 : 1;
- size -= box;
- counter -= size < 0 ? 1 : 0;
- }
- Console.WriteLine(size >= 0 ? "Congratulations! All suitcases are loaded!" : "No more space!");
- Console.WriteLine($"Statistic: {counter} suitcases loaded.");
- }
- }
- }
Add Comment
Please, Sign In to add comment