Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace EncodingSum
- {
- class Program
- {
- static void Main()
- {
- /* @ means end of input and printing result
- * digits 0-9 multiply the result by the value of the digit
- * letters - index is added to the result (note. alphabet starts with a 0 and ends in 25)
- * a "default" symbol means "moduling" the result (%)
- */
- double result = 0;
- double M = double.Parse(Console.ReadLine());
- string text = Console.ReadLine();
- foreach (char symbol in text)
- {
- if ((symbol >= 'A' && symbol <= 'Z') ||( symbol >= 'a' && symbol <= 'z'))
- {
- if (symbol >= 'A' && symbol <= 'Z')
- {
- result += symbol - 65;
- }
- if (symbol >= 'a' && symbol <= 'z')
- {
- result += symbol - 97;
- }
- }
- else if (symbol >= '0' && symbol <= '9')
- {
- int currentNumber = symbol - '0';
- result *= currentNumber;
- }
- else if ((symbol >= 0 && symbol <= 47) || (symbol >= 58 && symbol <= 63) || (symbol >= 91 && symbol <= 96) || (symbol >= 123 && symbol <= 255))
- {
- result = result % M;
- }
- else if (symbol == '@')
- {
- Console.WriteLine(result);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement