Advertisement
Aborigenius

*Phone*

Jun 22nd, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Phone
  8. {
  9.     class Program
  10.     {
  11.         static string[] phoneNumbers;
  12.         static string[] names;
  13.  
  14.         static void Main(string[] args)
  15.         {
  16.             phoneNumbers = Console.ReadLine().Split(' ');
  17.             names = Console.ReadLine().Split(' ');
  18.  
  19.             string[] input = Console.ReadLine().Split(' ');
  20.  
  21.             while (input[0] != "done")
  22.             {
  23.                 string command = input[0];
  24.                 string argument = input[1];
  25.                 string name = string.Empty;
  26.                 string number = String.Empty;
  27.                 string output = string.Empty;
  28.  
  29.                 if (IsNumber(argument) == true)
  30.                 {
  31.                     name = GetInputType(argument); ;
  32.                     number = argument;
  33.                     output = name;
  34.                 }
  35.                 else
  36.                 {
  37.                     name = argument;
  38.                     number = GetInputType(argument); ;
  39.                     output = number;
  40.                 }
  41.                 int digitSum = GetDigitsSum(number);
  42.                 if (command == "call")
  43.                 {
  44.                     Console.WriteLine($"calling {output}...");
  45.                     if (digitSum % 2 == 1)
  46.                     {
  47.                         Console.WriteLine("no answer");
  48.                     }
  49.                     else
  50.                     {
  51.                         int minutes = digitSum / 60;
  52.                         int seconds = digitSum % 60;
  53.                         Console.WriteLine($"call ended. duration: {minutes.ToString().PadLeft(2, '0')}:{seconds.ToString().PadLeft(2, '0')}");
  54.                     }
  55.  
  56.                 }
  57.                 else if (command == "message")
  58.                 {
  59.                     Console.WriteLine($"sending sms to {output}...");
  60.                     if (digitSum % 2 == 1)
  61.                     {
  62.  
  63.                         Console.WriteLine("busy");
  64.                     }
  65.                     else
  66.                     {
  67.                         Console.WriteLine("meet me there");
  68.                     }
  69.                 }
  70.                 input = Console.ReadLine().Split(' ');
  71.             }
  72.         }
  73.         static int GetDigitsSum(string phoneNumber)
  74.         {
  75.             int sum = 0;
  76.             for (int i = 0; i < phoneNumber.Length; i++)
  77.             {
  78.                 if (IsDigit(phoneNumber[i]))
  79.                 {
  80.                     sum += phoneNumber[i] - '0';
  81.                 }
  82.             }
  83.             return sum;
  84.         }
  85.         static string GetInputType(string input)
  86.         {
  87.             for (int i = 0; i < names.Length; i++)
  88.             {
  89.                 if (names[i] == input)
  90.                 {
  91.                     return phoneNumbers[i];
  92.                 }
  93.                 else if (phoneNumbers[i] == input)
  94.                 {
  95.                     return names[i];
  96.                 }
  97.             }
  98.             return string.Empty;
  99.         }
  100.  
  101.         static bool IsNumber(string input)
  102.         {
  103.             for (int cnt = 0; cnt < input.Length; cnt++)
  104.             {
  105.                 if (IsDigit(input[cnt]) == true)
  106.                 {
  107.                     return true;
  108.                 }
  109.             }
  110.             return false;
  111.         }
  112.         static bool IsDigit(char symbol)
  113.         {
  114.             return (symbol >= '0' && symbol <= '9');
  115.         }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement