Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace CleverLily
- {
- class Program
- {
- static void Main(string[] args)
- {
- int age = int.Parse(Console.ReadLine());
- double machine = double.Parse(Console.ReadLine());
- double toyPrice = double.Parse(Console.ReadLine());
- double sum = 0;
- int toy = 0;
- int birthday = 10;
- for (int i = 1; i <= age; i++)
- {
- if (i % 2 == 0)
- {
- sum += birthday - 1;
- birthday += 10;
- }
- else
- {
- toy++;
- }
- }
- sum += toy * toyPrice;
- if (sum >= machine)
- {
- Console.WriteLine($"Yes! {sum - machine:f2}");
- }
- else
- {
- Console.WriteLine($"No! {machine - sum:f2}");
- }
- }
- }
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- using System;
- namespace CleverLily
- {
- class Program
- {
- static void Main()
- {
- int age = int.Parse(Console.ReadLine());
- double machine = double.Parse(Console.ReadLine());
- double toyPrice = double.Parse(Console.ReadLine());
- int toy = 0, birthday = 10;
- for (int i = 1; i <= age; i++)
- {
- _machine -= i % 2 == 0 ? 5 * i - 1 : toyPrice;
- }
- Console.WriteLine($"{(machine > 0 ? "No" : "Yes")}! {Math.Abs(machine):f2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement