Advertisement
Pip3r4o

Encoding Nums

Feb 5th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 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 EncodingSum
  8. {
  9. class Program
  10. {
  11. static void Main()
  12. {
  13. /* @ means end of input and printing result
  14. * digits 0-9 multiply the result by the value of the digit
  15. * letters - index is added to the result (note. alphabet starts with a 0 and ends in 25)
  16. * a "default" symbol means "moduling" the result (%)
  17. */
  18.  
  19. double result = 0;
  20.  
  21. double M = double.Parse(Console.ReadLine());
  22. string text = Console.ReadLine();
  23.  
  24. foreach (char symbol in text)
  25. {
  26. if ((symbol >= 'A' && symbol <= 'Z') ||( symbol >= 'a' && symbol <= 'z'))
  27. {
  28. if (symbol >= 'A' && symbol <= 'Z')
  29. {
  30. result += symbol - 65;
  31. }
  32. if (symbol >= 'a' && symbol <= 'z')
  33. {
  34. result += symbol - 97;
  35. }
  36.  
  37. }
  38. else if (symbol >= '0' && symbol <= '9')
  39. {
  40. int currentNumber = symbol - '0';
  41. result *= currentNumber;
  42. }
  43. else if ((symbol >= 0 && symbol <= 47) || (symbol >= 58 && symbol <= 63) || (symbol >= 91 && symbol <= 96) || (symbol >= 123 && symbol <= 255))
  44. {
  45. result = result % M;
  46. }
  47. else if (symbol == '@')
  48. {
  49. Console.WriteLine(result);
  50. }
  51. }
  52.  
  53.  
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement