iliya87

02.Numerology

Mar 25th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System;
  2.  
  3. class Numerology
  4. {
  5.     static void Main()
  6.     {
  7.         string[] input = Console.ReadLine().Split('.', ' ');
  8.  
  9.         int day = int.Parse(input[0]);
  10.         int month = int.Parse(input[1]);
  11.         int year = int.Parse(input[2]);
  12.         string username = input[3];
  13.  
  14.         long result = day * month * year;
  15.  
  16.         if (month % 2 == 1)
  17.         {
  18.             result *= result;
  19.         }
  20.  
  21.         for (int i = 0; i < username.Length; i++)
  22.         {
  23.             char currentChar = username[i];
  24.  
  25.             if (currentChar >= '0' && currentChar <= '9')
  26.             {
  27.                 result += currentChar - '0';
  28.             }
  29.             else if (currentChar >= 'a' && currentChar <= 'z')
  30.             {
  31.                 result += currentChar - 'a' + 1;
  32.             }
  33.             else if (currentChar >= 'A' && currentChar <= 'Z')
  34.             {
  35.                 result += 2 * (currentChar - 'A' + 1);
  36.             }
  37.         }        
  38.  
  39.         while (result > 13)
  40.         {
  41.             int digitSum = 0;
  42.  
  43.             while (result > 0)
  44.             {
  45.                 digitSum += (int)(result % 10);
  46.                 result /= 10;
  47.             }
  48.  
  49.             result = digitSum;
  50.         }
  51.  
  52.         Console.WriteLine(result);
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment