damyan91

Untitled

Jun 10th, 2017
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 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 _14.Letters_Change_Numbers
  8. {
  9. public class LettersChangeNums
  10. {
  11. public static void Main()
  12. {
  13. string[] line = Console.ReadLine()
  14. .Split(new[] {' ', '\t', '\n', '\r'}, StringSplitOptions.RemoveEmptyEntries);
  15. int position = 0;
  16. decimal sum = 0M;
  17. decimal total = 0M;
  18.  
  19.  
  20. foreach (var str in line)
  21. {
  22. char firstLetter = str[0];
  23. char secondLetter = str[str.Length - 1];
  24. decimal num = decimal.Parse(str.Substring(1, str.Length - 2));
  25.  
  26. if (Char.IsUpper(firstLetter))
  27. {
  28. position = (int)firstLetter - (int)'A' + 1;
  29. sum = num / position;
  30. }
  31. if (Char.IsLower(firstLetter))
  32. {
  33. position = (int)firstLetter - (int)'a' + 1;
  34. sum = num * position;
  35. }
  36. if(Char.IsUpper(secondLetter))
  37. {
  38. position = (int)secondLetter - (int)'A' + 1;
  39. sum -= position;
  40. }
  41. if (Char.IsLower(secondLetter))
  42. {
  43. position = (int)secondLetter - (int)'a' + 1;
  44. sum += position;
  45. }
  46.  
  47. total += sum;
  48. sum = 0;
  49. }
  50.  
  51. Console.WriteLine("{0:f2}", total);
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment