Advertisement
bullit3189

LetterChangeNumbers-StringAndRegex

Mar 20th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5. using System.Text;
  6.  
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. string[] input = Console.ReadLine().Split(new [] {' ','\t'},StringSplitOptions.RemoveEmptyEntries);
  12.  
  13. decimal result =0;
  14.  
  15. foreach (string entry in input)
  16. {
  17. char firstLetter = entry[0];
  18. char lastLetter = entry[entry.Length-1];
  19.  
  20. int len = entry.Length-2;
  21. string numAsString = entry.Substring(1,len);
  22. decimal num = decimal.Parse(numAsString);
  23.  
  24. if (char.IsUpper(firstLetter))
  25. {
  26. int position = (int) firstLetter - 64;
  27.  
  28. result += num / position;
  29.  
  30. }
  31. else if (char.IsLower(firstLetter))
  32. {
  33. int position = (int) firstLetter - 96;
  34.  
  35. result += num*position;
  36.  
  37. }
  38.  
  39. if (char.IsUpper(lastLetter))
  40. {
  41. int position = (int) lastLetter -64;
  42.  
  43. result -= position;
  44.  
  45. }
  46. else if (char.IsLower(lastLetter))
  47. {
  48. int position = (int) lastLetter-96;
  49.  
  50. result += position;
  51.  
  52. }
  53. }
  54.  
  55. Console.WriteLine("{0:f2}",result);
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement