Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Phone
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] phones = Console.ReadLine().Split(' ');
- string[] names = Console.ReadLine().Split(' ');
- string dial = string.Empty;
- while (dial != "done")
- {
- dial = Console.ReadLine();
- for (int i = 0; i < names.Length; i++)
- {
- if (dial == "call "+names[i] || dial == "call "+phones[i])
- {
- if (dial == "call " + names[i])
- {
- Console.WriteLine($"calling {phones[i]}...");
- Console.WriteLine(CallingMessage(phones[i]));
- }
- else if (dial == "call " + phones[i])
- {
- Console.WriteLine($"calling {names[i]}...");
- Console.WriteLine(CallingMessage(phones[i]));
- }
- }
- if (dial == "message " + names[i] || dial == "message " + phones[i])
- {
- if (dial == "message " + names[i])
- {
- Console.WriteLine($"sending sms to {phones[i]}...");
- Console.WriteLine(SmsMessage(phones[i]));
- }
- else if (dial == "message " + phones[i])
- {
- Console.WriteLine($"sending sms to {names[i]}...");
- Console.WriteLine(SmsMessage(phones[i]));
- }
- else
- {
- break;
- }
- }
- }
- }
- }
- static string CallingMessage(string phone)
- {
- int sumDigitsPhone = SumDigits(phone);
- string message = string.Empty;
- if (sumDigitsPhone % 2 == 0)
- {
- int mins = (int)sumDigitsPhone / 60;
- int secs = (int)sumDigitsPhone % 60;
- message = $"call ended. duration: {mins:d2}:{secs:d2}";
- }
- else if (sumDigitsPhone % 2 != 0)
- {
- message = "no answer";
- }
- return message;
- }
- static string SmsMessage(string phone)
- {
- int differenceDigitsPhone = DifferenceDigits(phone);
- string message = string.Empty;
- if (Math.Abs(differenceDigitsPhone) % 2 == 0)
- {
- message = "meet me there";
- }
- else if (Math.Abs(differenceDigitsPhone) % 2 != 0)
- {
- message = "busy";
- }
- return message;
- }
- static int SumDigits(string phone)
- {
- char[] newPhone = phone.ToCharArray();
- int sumDigits = 0;
- for (int i = 0; i < newPhone.Length; i++)
- {
- if ((int)newPhone[i] >= 48 && (int)newPhone[i] <= 57)
- {
- sumDigits += (int)newPhone[i] - 48;
- }
- }
- return sumDigits;
- }
- static int DifferenceDigits(string phone)
- {
- char[] newPhone = phone.ToCharArray();
- int differenceDigits = 0;
- for (int i = 0; i < newPhone.Length; i++)
- {
- if ((int)newPhone[i] >= 48 && (int)newPhone[i] <= 57)
- {
- differenceDigits += (int)newPhone[i] - 48;
- }
- }
- return differenceDigits;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement