Advertisement
Guest User

Untitled

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