Advertisement
Guest User

Untitled

a guest
Oct 19th, 2016
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 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. number = double.Parse(item.Substring(1, item.Length - 2));
  29. }
  30.  
  31. sum = GetFirstSum(firstIndex, number);
  32. sum = GetSecondSum(secondIndex, sum);
  33. totalSum += sum;
  34. }
  35. }
  36.  
  37. Console.WriteLine($"{totalSum:f2}");
  38. }
  39.  
  40. private static double GetSecondSum(char secondIndex, double sum)
  41. {
  42. double secondSum = sum;
  43. double pos = GetPosition(secondIndex);
  44.  
  45. if (secondIndex >= 'a' && secondIndex <= 'z')
  46. {
  47. secondSum += pos;
  48. }
  49. else if (secondIndex >= 'A' && secondIndex <= 'Z')
  50. {
  51. secondSum -= pos;
  52. }
  53.  
  54. return secondSum;
  55. }
  56.  
  57. private static double GetFirstSum(char firstIndex, double number)
  58. {
  59. double sum = 0;
  60. double pos = GetPosition(firstIndex);
  61.  
  62. if (firstIndex >= 'a' && firstIndex <= 'z')
  63. {
  64. sum = number * pos;
  65. }
  66. else if (firstIndex >= 'A' && firstIndex <= 'Z')
  67. {
  68. sum = number / pos;
  69. }
  70.  
  71. return sum;
  72. }
  73.  
  74. private static double GetPosition(char index)
  75. {
  76. double count = 0;
  77.  
  78. char chek = char.ToLower(index);
  79.  
  80. for (int i = 'a'; i <= 'z'; i++)
  81. {
  82. if (i > chek)
  83. {
  84. break;
  85. }
  86. count++;
  87. }
  88. return count;
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement