terlichki

Untitled

Jun 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 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. using System.Numerics;
  7. using System.Text.RegularExpressions;
  8.  
  9.  
  10. namespace Letters_Change_Numbers
  11. {
  12. class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. string[] input = "P34562Z q2576f H456z"//Console.ReadLine()
  17. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  18. StringBuilder partition = new StringBuilder();
  19. double finalResult = 0;
  20. for (int i = 0; i < input.Length; i++)
  21. {
  22. partition.Append(input[i]);
  23. var firstL = partition[0];
  24. var firstR = partition[partition.Length - 1];
  25. int midleL = int.Parse(getMatches(input[i]));
  26. double forFirstArr = getMathResult(firstL, firstR, midleL);
  27. finalResult += forFirstArr;
  28. Console.WriteLine(finalResult);
  29. partition.Clear();
  30. }
  31.  
  32. }
  33.  
  34. static string getMatches(string n) {
  35. string patern = @"\d+";// за цифрите в средата
  36. Regex regex = new Regex(patern);
  37. Match match = regex.Match(n);
  38. string midle = "";
  39. if (match.Success)
  40. {
  41. midle = match.Value;
  42. }
  43. return
  44. (midle);
  45. }
  46.  
  47. static double getMathResult(char first, char second, int midle)
  48. {
  49. double sum = 0;
  50. if (first >= 65 && first<90)
  51. {
  52. sum = midle / (first - 64);
  53.  
  54. }
  55. else if (first>=95 && first<=122)
  56. {
  57. sum = midle * (first - 96);
  58. }
  59. if (second >= 95 && second <= 122)
  60. {
  61. sum +=(second - 96);
  62. }
  63. if (second >= 65 && second <= 90)
  64. {
  65. sum -=(second - 64);
  66. }
  67.  
  68. return
  69. (sum);
  70. }
  71.  
  72.  
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment