Guest User

Untitled

a guest
Oct 19th, 2016
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 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. class Program
  8. {
  9. static void Main()
  10. {
  11. string[] input = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  12.  
  13. double totalSum = 0;
  14.  
  15. foreach (var item in input)
  16. {
  17. if (item.Length > 1)
  18. {
  19. double sum = 0;
  20.  
  21. char firstIndex = item[0];
  22. char secondIndex = item[item.Length - 1];
  23.  
  24. double number = 0.0;
  25.  
  26. if (item.Length > 2)
  27. {
  28. try
  29. {
  30. number = double.Parse(item.Substring(1, item.Length - 2));
  31. }
  32. catch (Exception)
  33. {
  34. continue;
  35. }
  36. }
  37.  
  38. sum = GetFirstSum(firstIndex, number);
  39. sum = GetSecondSum(secondIndex, sum);
  40. totalSum += sum;
  41. }
  42. }
  43.  
  44. Console.WriteLine($"{totalSum:f2}");
  45. }
  46.  
  47. private static double GetSecondSum(char secondIndex, double sum)
  48. {
  49. double secondSum = sum;
  50. double pos = GetPosition(secondIndex);
  51.  
  52. if (secondIndex >= 'a' && secondIndex <= 'z')
  53. {
  54. secondSum += pos;
  55. }
  56. else if (secondIndex >= 'A' && secondIndex <= 'Z')
  57. {
  58. secondSum -= pos;
  59. }
  60.  
  61. return secondSum;
  62. }
  63.  
  64. private static double GetFirstSum(char firstIndex, double number)
  65. {
  66. double sum = 0;
  67. double pos = GetPosition(firstIndex);
  68.  
  69. if (firstIndex >= 'a' && firstIndex <= 'z')
  70. {
  71. sum = number * pos;
  72. }
  73. else if (firstIndex >= 'A' && firstIndex <= 'Z')
  74. {
  75. sum = number / pos;
  76. }
  77.  
  78. return sum;
  79. }
  80.  
  81. private static double GetPosition(char index)
  82. {
  83. double count = 0;
  84.  
  85. char chek = char.ToLower(index);
  86.  
  87. for (int i = 'a'; i <= 'z'; i++)
  88. {
  89. if (i > chek)
  90. {
  91. break;
  92. }
  93. count++;
  94. }
  95. return count;
  96. }
  97. }
Add Comment
Please, Sign In to add comment