Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Moving
- {
- class Program
- {
- static void Main(string[] args)
- {
- int width = int.Parse(Console.ReadLine());
- int length = int.Parse(Console.ReadLine());
- int height = int.Parse(Console.ReadLine());
- int volume = width * length * height;
- int totalbox = 0;
- while (true)
- {
- string box = Console.ReadLine();
- if (box == "Done")
- {
- Console.WriteLine($"{volume - totalbox} Cubic meters left.");
- break;
- }
- totalbox += int.Parse(box);
- if (volume <= totalbox)
- {
- Console.WriteLine($"No more free space! You need {totalbox - volume} Cubic meters more.");
- break;
- }
- }
- }
- }
- }
- ИЛИ ТАКА:
- using System;
- namespace Moving
- {
- class Program
- {
- static void Main(string[] args)
- {
- int width = int.Parse(Console.ReadLine());
- int length = int.Parse(Console.ReadLine());
- int height = int.Parse(Console.ReadLine());
- int volume = width * length * height;
- while (true)
- {
- string box = Console.ReadLine();
- if (box == "Done")
- {
- Console.WriteLine($"{volume} Cubic meters left.");
- break;
- }
- volume -= int.Parse(box);
- if (volume <= 0)
- {
- Console.WriteLine($"No more free space! You need {Math.Abs(volume)} Cubic meters more.");
- break;
- }
- }
- }
- }
- }
- РЕШЕНИЕ С FOR:
- using System;
- namespace Moving
- {
- class Program
- {
- static void Main(string[] args)
- {
- int width = int.Parse(Console.ReadLine());
- int length = int.Parse(Console.ReadLine());
- int height = int.Parse(Console.ReadLine());
- int volume = width * length * height;
- for (int i = 0; volume > 0; i++)
- {
- string box = Console.ReadLine();
- if (box == "Done")
- {
- break;
- }
- volume -= int.Parse(box);
- }
- if (volume > 0)
- {
- Console.WriteLine($"{volume} Cubic meters left.");
- }
- else
- {
- Console.WriteLine($"No more free space! You need {Math.Abs(volume)} Cubic meters more.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement