Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- РЕШЕНИЕ СЪС SWITCH:
- using System;
- namespace SmallShop
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string product = Console.ReadLine();
- string town = Console.ReadLine();
- double quantity = double.Parse(Console.ReadLine());
- double sum = 0;
- switch (town)
- {
- case "Sofia":
- switch (product)
- {
- case "coffee":
- sum = 0.5;
- break;
- case "water":
- sum = 0.8;
- break;
- case "beer":
- sum = 1.2;
- break;
- case "sweets":
- sum = 1.45;
- break;
- case "peanuts":
- sum = 1.6;
- break;
- }
- break;
- case "Plovdiv":
- switch (product)
- {
- case "coffee":
- sum = 0.4;
- break;
- case "water":
- sum = 0.7;
- break;
- case "beer":
- sum = 1.15;
- break;
- case "sweets":
- sum = 1.3;
- break;
- case "peanuts":
- sum = 1.5;
- break;
- }
- break;
- case "Varna":
- switch (product)
- {
- case "coffee":
- sum = 0.45;
- break;
- case "water":
- sum = 0.7;
- break;
- case "beer":
- sum = 1.1;
- break;
- case "sweets":
- sum = 1.35;
- break;
- case "peanuts":
- sum = 1.55;
- break;
- }
- break;
- }
- Console.WriteLine(sum * quantity);
- }
- }
- }
- РЕШЕНИЕ СЪС IF-ELSE:
- using System;
- namespace SmallShop
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string product = Console.ReadLine();
- string town = Console.ReadLine();
- double quantity = double.Parse(Console.ReadLine());
- double sum = 0;
- if (town == "Sofia")
- {
- if (product == "coffee")
- {
- sum = 0.5;
- }
- else if (product == "water")
- {
- sum = 0.8;
- }
- else if (product == "beer")
- {
- sum = 1.2;
- }
- else if (product == "sweets")
- {
- sum = 1.45;
- }
- else if (product == "peanuts")
- {
- sum = 1.6;
- }
- }
- else if (town == "Plovdiv")
- {
- if (product == "coffee")
- {
- sum = 0.4;
- }
- else if (product == "water")
- {
- sum = 0.7;
- }
- else if (product == "beer")
- {
- sum = 1.15;
- }
- else if (product == "sweets")
- {
- sum = 1.3;
- }
- else if (product == "peanuts")
- {
- sum = 1.5;
- }
- }
- else if (town == "Varna")
- {
- if (product == "coffee")
- {
- sum = 0.45;
- }
- else if (product == "water")
- {
- sum = 0.7;
- }
- else if (product == "beer")
- {
- sum = 1.1;
- }
- else if (product == "sweets")
- {
- sum = 1.35;
- }
- else if (product == "peanuts")
- {
- sum = 1.55;
- }
- }
- Console.WriteLine(sum * quantity);
- }
- }
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- using System;
- namespace SmallShop
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string product = Console.ReadLine();
- string town = Console.ReadLine();
- double quantity = double.Parse(Console.ReadLine());
- double sum = product == "coffee" ? (town == "Sofia" ? 0.5 : town == "Plovdiv" ? 0.4 : town == "Varna" ? 0.45 : 0) :
- product == "water" ? (town == "Sofia" ? 0.8 : town == "Plovdiv" ? 0.7 : town == "Varna" ? 0.7 : 0) :
- product == "beer" ? (town == "Sofia" ? 1.2 : town == "Plovdiv" ? 1.15 : town == "Varna" ? 1.1 : 0) :
- product == "sweets" ? (town == "Sofia" ? 1.45 : town == "Plovdiv" ? 1.3 : town == "Varna" ? 1.35 : 0) :
- product == "peanuts" ? (town == "Sofia" ? 1.6 : town == "Plovdiv" ? 1.5 : town == "Varna" ? 1.55 : 0) : 0;
- Console.WriteLine(sum * quantity);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement