Advertisement
pavsavov

08. Letters Change Numbers

Oct 28th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 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 LettersChangeNumb
  8. {
  9. class LettersChangeN
  10. {
  11. public static decimal IterationthroughWords(char[] currentword)
  12. {
  13. decimal currentOperationsFirst = 0;
  14. for (int i = 0; i < currentword.Length; i++)
  15. {
  16. char beforeLetter = currentword.First();
  17. char afterLetter = currentword.Last();
  18. decimal number = ParseStringToInt(currentword);
  19.  
  20. if (char.IsUpper(beforeLetter)) // Before -> Upper -> Divide
  21. {
  22. decimal beforeLetterPosition = LowerOrUpperCasePositioning(beforeLetter); //Позиция на 1-а буква в азбуката,при главна буква
  23. currentOperationsFirst = number / beforeLetterPosition;
  24. number = currentOperationsFirst;
  25.  
  26. }
  27. else if (char.IsLower(beforeLetter)) // Before -> Lower -> Multiply
  28. {
  29. decimal beforePosition = LowerOrUpperCasePositioning(beforeLetter); //Позиция на 1-а буква в азбуката,при малка буква
  30. currentOperationsFirst = number * beforePosition;
  31. number = currentOperationsFirst;
  32. }
  33. if (char.IsUpper(afterLetter)) // After -> Upper -> Substract
  34. {
  35. decimal afterPosition = LowerOrUpperCasePositioning(afterLetter); //Позиция на 2-а буква в азбуката,при главна буква
  36. currentOperationsFirst = number - afterPosition;
  37. number = currentOperationsFirst;
  38. }
  39. else if (char.IsLower(afterLetter)) // After -> Lower -> Add
  40. {
  41. decimal afterPostion = LowerOrUpperCasePositioning(afterLetter); //Позиция на 2-а буква в азбуката,при малка буква
  42. currentOperationsFirst = number + afterPostion;
  43. number = currentOperationsFirst;
  44. }
  45. }
  46. return currentOperationsFirst;
  47. }
  48. public static decimal LowerOrUpperCasePositioning(char letter)
  49. {
  50. decimal indexOfLetter = 0;
  51. if (char.IsLower(letter))
  52. {
  53. string alphabet = "abcdefghijklmnopqrstuvwxyz";
  54. indexOfLetter = (alphabet.IndexOf(letter)) + 1;
  55. }
  56. else if (char.IsUpper(letter))
  57. {
  58. string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  59. indexOfLetter = (alphabet.IndexOf(letter)) + 1;
  60. }
  61. return indexOfLetter;
  62. }
  63. public static decimal ParseStringToInt(char[] letters)
  64. {
  65.  
  66. String s = new string(letters);
  67. var removeFirst = s.Remove(0, 1);
  68. var removeLast = removeFirst.Remove(removeFirst.Length - 1, 1);
  69. decimal number = decimal.Parse(removeLast);
  70.  
  71. return number;
  72. }
  73. static void Main(string[] args)
  74. {
  75. string[] input = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  76. decimal totalSumFirstChar = 0;
  77.  
  78. if (input.Length >= 1 || input.Length <= 10)
  79. {
  80. for (int i = 0; i < input.Length; i++)
  81. {
  82. char[] word = input[i].ToArray();
  83. totalSumFirstChar += IterationthroughWords(word);
  84. }
  85. Console.WriteLine("{0:F2}", totalSumFirstChar);
  86. }
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement