Advertisement
anilak

ExamC1 24.06.2013 Secrets

Jun 25th, 2013
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5.     class Secreats
  6.     {
  7.         static void Main()
  8.         {
  9.             ulong specialSum = 0;
  10.             string num = Console.ReadLine();
  11.             byte alphaSeqLength = 0;
  12.             ushort step = 1;
  13.             for (int i = num.Length - 1; i >= 0; i--, step++)
  14.             {
  15.                 int temp = 0;
  16.                 if (Char.IsDigit(num[i]))
  17.                 {
  18.                     temp = int.Parse(num[i].ToString());
  19.                 }
  20.                 else
  21.                 {
  22.                     continue;
  23.                 }
  24.                 if ((step & 1) == 1)
  25.                 {
  26.                     specialSum += (ulong)(step * step * temp);
  27.                 }
  28.                 else
  29.                 {
  30.                     specialSum += (ulong)(step * temp * temp);
  31.                 }
  32.             }
  33.             alphaSeqLength = (byte)(specialSum % 10);
  34.             StringBuilder alphaSeq = new StringBuilder();
  35.             sbyte startLetter = (sbyte)(specialSum % 26);
  36.             for (byte i = 0; i < alphaSeqLength; i++)
  37.             {
  38.                 if (startLetter + 'A' + i > 'Z')
  39.                 {
  40.                     startLetter = (sbyte)(-i);
  41.                 }
  42.                 alphaSeq.Append((char)(startLetter + 'A' + i));
  43.             }
  44.             if (num != "")
  45.             {
  46.                 Console.WriteLine(specialSum);
  47.             }
  48.             if (alphaSeqLength != 0)
  49.             {
  50.                 Console.WriteLine(alphaSeq.ToString());
  51.             }
  52.             else
  53.             {
  54.                 Console.WriteLine("{0} has no secret alpha-sequence", num);
  55.             }
  56.         }
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement