Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Phone
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- List<string> listOfNumbers = Console.ReadLine().Split().ToList();
- List<string> listOfNames = Console.ReadLine().Split().ToList();
- List<string> resultNames = new List<string>();
- List<string> resultNumbers = new List<string>();
- string command = string.Empty;
- while ((command = Console.ReadLine()) != "done")
- {
- string[] commandArray = command.Split();
- if (commandArray[0] == "call" && listOfNumbers.Exists(x => x == commandArray[1]))
- {
- string phoneNumber = commandArray[1];
- int phoneIndex = listOfNumbers.IndexOf(phoneNumber);
- string name = listOfNames[phoneIndex];
- Console.WriteLine($"calling {name}...");
- CalculateSumOfDigitsAndPrintAnswer(phoneNumber);
- }
- else if (commandArray[0] == "call" && listOfNames.Exists(x => x == commandArray[1]))
- {
- string name = commandArray[1];
- int indexOfName = listOfNames.IndexOf(name);
- string phoneNumber = listOfNumbers[indexOfName];
- Console.WriteLine($"calling {phoneNumber}...");
- CalculateSumOfDigitsAndPrintAnswer(phoneNumber);
- }
- else if (commandArray[0] == "message" && listOfNumbers.Exists(x => x == commandArray[1]))
- {
- string phoneNumber = commandArray[1];
- int phoneIndex = listOfNumbers.IndexOf(phoneNumber);
- string name = listOfNames[phoneIndex];
- Console.WriteLine(($"sending sms to {name}..."));
- CalculateDifferenceOfDigitsAndPrintAnswer(phoneNumber);
- }
- else if (commandArray[0] == "message" && listOfNames.Exists(x => x == commandArray[1]))
- {
- string name = commandArray[1];
- int indexOfName = listOfNames.IndexOf(name);
- string phoneNumber = listOfNumbers[indexOfName];
- Console.WriteLine($"sending sms to {phoneNumber}...");
- CalculateDifferenceOfDigitsAndPrintAnswer(phoneNumber);
- }
- }
- }
- private static void CalculateDifferenceOfDigitsAndPrintAnswer(string phoneNumber)
- {
- int difference = 0;
- for (int i = 0; i < phoneNumber.Length; i++)
- {
- if (int.TryParse(phoneNumber[i].ToString(), out int result)) // TryParse()
- {
- difference = difference - result;
- }
- }
- if (difference % 2 != 0)
- {
- Console.WriteLine("busy");
- }
- else if (difference % 2 == 0)
- {
- Console.WriteLine("meet me there");
- }
- }
- private static void CalculateSumOfDigitsAndPrintAnswer(string phoneNumber)
- {
- int sum = 0;
- for (int i = 0; i < phoneNumber.Length; i++)
- {
- if (int.TryParse(phoneNumber[i].ToString(), out int result)) // TryParse()
- {
- sum += result;
- }
- }
- if (sum % 2 != 0)
- {
- Console.WriteLine("no answer");
- }
- else if (sum % 2 == 0)
- {
- int minutes = sum / 60;
- int secundes = sum % 60;
- Console.WriteLine($"call ended. duration: {minutes:D2}:{secundes:D2}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement