Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Salary
- {
- class Program
- {
- static void Main(string[] args)
- {
- int tabs = int.Parse(Console.ReadLine());
- int salary = int.Parse(Console.ReadLine());
- for (int i = 0; i < tabs && salary > 0; i++)
- {
- string apps = Console.ReadLine();
- if (apps == "Facebook")
- {
- salary -= 150;
- }
- if (apps == "Instagram")
- {
- salary -= 100;
- }
- if (apps == "Reddit")
- {
- salary -= 50;
- }
- }
- if (salary > 0)
- {
- Console.WriteLine(salary);
- }
- else
- {
- Console.WriteLine("You have lost your salary.");
- }
- }
- }
- }
- Решение с for и тернарен оператор:
- using System;
- namespace Salary
- {
- class Program
- {
- static void Main(string[] args)
- {
- int tabs = int.Parse(Console.ReadLine());
- int salary = int.Parse(Console.ReadLine());
- for (int i = 0; i < tabs && salary > 0; i++)
- {
- string apps = Console.ReadLine();
- salary -= apps == "Facebook" ? 150 : apps == "Instagram" ? 100 : apps == "Reddit" ? 50 : 0;
- }
- Console.WriteLine(salary > 0 ? $"{salary}" : "You have lost your salary.");
- }
- }
- }
- Решение с while:
- using System;
- namespace Salary
- {
- class Program
- {
- static void Main(string[] args)
- {
- int tabs = int.Parse(Console.ReadLine());
- int salary = int.Parse(Console.ReadLine());
- while ( tabs != 0 && salary > 0)
- {
- string apps = Console.ReadLine();
- if (apps == "Facebook")
- {
- salary -= 150;
- }
- if (apps == "Instagram")
- {
- salary -= 100;
- }
- if (apps == "Reddit")
- {
- salary -= 50;
- }
- tabs--;
- }
- if (salary > 0)
- {
- Console.WriteLine(salary);
- }
- else
- {
- Console.WriteLine("You have lost your salary.");
- }
- }
- }
- }
- Решение с while и тернарен оператор:
- using System;
- namespace Salary
- {
- class Program
- {
- static void Main(string[] args)
- {
- int tabs = int.Parse(Console.ReadLine());
- int salary = int.Parse(Console.ReadLine());
- while (tabs != 0 && salary > 0)
- {
- string apps = Console.ReadLine();
- salary -= apps == "Facebook" ? 150 : apps == "Instagram" ? 100 : apps == "Reddit" ? 50 : 0;
- tabs--;
- }
- Console.WriteLine(salary > 0 ? $"{salary}" : "You have lost your salary.");
- }
- }
- }
Add Comment
Please, Sign In to add comment