Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- class Phone
- {
- static void Main()
- {
- var phones = Console.ReadLine().Split();
- var names = Console.ReadLine().Split();
- var func = Console.ReadLine().Split();
- while (func[0] != "done")
- {
- var match = func[1];
- var duration = 0.00;
- var difference = 0;
- var isPhone = false;
- var matchedPhone = String.Empty;
- var matchedName = String.Empty;
- for (int i = 0; i < phones.Length; i++)
- {
- if (match == phones[i])
- {
- matchedPhone = phones[i];
- matchedName = names[i];
- isPhone = true;
- break;
- }
- else if (match == names[i])
- {
- isPhone = false;
- matchedPhone = phones[i];
- matchedName = names[i];
- break;
- }
- }
- switch (func[0])
- {
- case "call":
- duration = CalcDuration(matchedPhone);
- var start = "00:00";
- var startTime = DateTime.ParseExact(start,"mm:ss",CultureInfo.InvariantCulture);
- startTime=startTime.AddSeconds(duration );
- if (isPhone)
- {
- Console.WriteLine("calling {0}...", matchedName);
- if (duration % 2 == 1)
- {
- Console.WriteLine("no answer");
- }
- else
- {
- Console.WriteLine("call ended. duration: {0}", startTime.ToString("mm:ss"));
- }
- }
- else
- {
- duration = CalcDuration(matchedPhone);
- Console.WriteLine("calling {0}...", matchedPhone);
- if (duration % 2 == 1)
- {
- Console.WriteLine("no answer");
- }
- else
- {
- Console.WriteLine("call ended. duration: {0}", startTime.ToString("mm:ss"));
- }
- }
- break;
- case "message":
- if (isPhone)
- {
- difference = CalcDifference(matchedPhone);
- Console.WriteLine("sending sms to {0}...", matchedName);
- if (difference % 2 == 1)
- {
- Console.WriteLine("busy");
- }
- else
- {
- Console.WriteLine("meet me there");
- }
- }
- else
- {
- difference = CalcDifference(matchedPhone);
- Console.WriteLine("sending sms to {0}...", matchedPhone);
- if (Math.Abs(difference) % 2 == 1)
- {
- Console.WriteLine("busy");
- }
- else
- {
- Console.WriteLine("meet me there");
- }
- }
- break;
- default:
- break;
- }
- func = Console.ReadLine().Split();
- }
- }
- private static int CalcDifference(string phone)
- {
- var difference = 0;
- for (int p = 0; p < phone.Length; p++)
- {
- if (char.IsDigit(phone[p]))
- {
- var digit = char.GetNumericValue(phone[p]);
- difference -= int.Parse(digit.ToString());
- }
- }
- return difference;
- }
- private static double CalcDuration(string phone)
- {
- var duration = 0.00;
- for (int p = 0; p < phone.Length; p++)
- {
- if (char.IsDigit(phone[p]))
- {
- var digit = char.GetNumericValue(phone[p]);
- duration +=double.Parse( digit.ToString());
- }
- }
- duration = duration % 86400;
- return duration;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement