Advertisement
NonaG

Phone

Feb 14th, 2017
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. class Phone
  9. {
  10. static void Main()
  11. {
  12. var phones = Console.ReadLine().Split();
  13. var names = Console.ReadLine().Split();
  14. var func = Console.ReadLine().Split();
  15. while (func[0] != "done")
  16. {
  17. var match = func[1];
  18. var duration = 0.00;
  19. var difference = 0;
  20. var isPhone = false;
  21. var matchedPhone = String.Empty;
  22. var matchedName = String.Empty;
  23. for (int i = 0; i < phones.Length; i++)
  24. {
  25. if (match == phones[i])
  26. {
  27. matchedPhone = phones[i];
  28. matchedName = names[i];
  29. isPhone = true;
  30. break;
  31. }
  32. else if (match == names[i])
  33. {
  34. isPhone = false;
  35. matchedPhone = phones[i];
  36. matchedName = names[i];
  37. break;
  38. }
  39. }
  40. switch (func[0])
  41. {
  42. case "call":
  43. duration = CalcDuration(matchedPhone);
  44. var start = "00:00";
  45. var startTime = DateTime.ParseExact(start,"mm:ss",CultureInfo.InvariantCulture);
  46. startTime=startTime.AddSeconds(duration );
  47. if (isPhone)
  48. {
  49.  
  50. Console.WriteLine("calling {0}...", matchedName);
  51. if (duration % 2 == 1)
  52. {
  53. Console.WriteLine("no answer");
  54. }
  55. else
  56. {
  57. Console.WriteLine("call ended. duration: {0}", startTime.ToString("mm:ss"));
  58. }
  59. }
  60. else
  61. {
  62. duration = CalcDuration(matchedPhone);
  63. Console.WriteLine("calling {0}...", matchedPhone);
  64. if (duration % 2 == 1)
  65. {
  66. Console.WriteLine("no answer");
  67. }
  68. else
  69. {
  70. Console.WriteLine("call ended. duration: {0}", startTime.ToString("mm:ss"));
  71. }
  72. }
  73. break;
  74. case "message":
  75. if (isPhone)
  76. {
  77. difference = CalcDifference(matchedPhone);
  78. Console.WriteLine("sending sms to {0}...", matchedName);
  79. if (difference % 2 == 1)
  80. {
  81. Console.WriteLine("busy");
  82. }
  83. else
  84. {
  85. Console.WriteLine("meet me there");
  86. }
  87. }
  88. else
  89. {
  90. difference = CalcDifference(matchedPhone);
  91. Console.WriteLine("sending sms to {0}...", matchedPhone);
  92. if (Math.Abs(difference) % 2 == 1)
  93. {
  94. Console.WriteLine("busy");
  95. }
  96. else
  97. {
  98. Console.WriteLine("meet me there");
  99. }
  100. }
  101. break;
  102. default:
  103. break;
  104. }
  105. func = Console.ReadLine().Split();
  106. }
  107. }
  108.  
  109. private static int CalcDifference(string phone)
  110. {
  111. var difference = 0;
  112. for (int p = 0; p < phone.Length; p++)
  113. {
  114. if (char.IsDigit(phone[p]))
  115. {
  116. var digit = char.GetNumericValue(phone[p]);
  117. difference -= int.Parse(digit.ToString());
  118. }
  119. }
  120. return difference;
  121. }
  122. private static double CalcDuration(string phone)
  123. {
  124.  
  125. var duration = 0.00;
  126. for (int p = 0; p < phone.Length; p++)
  127. {
  128. if (char.IsDigit(phone[p]))
  129. {
  130. var digit = char.GetNumericValue(phone[p]);
  131. duration +=double.Parse( digit.ToString());
  132. }
  133. }
  134. duration = duration % 86400;
  135.  
  136. return duration;
  137. }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement