Advertisement
ivan_yosifov

Secret_Number

Nov 13th, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System;
  2.  
  3. class SecretNumber
  4. {
  5.     static void Main()
  6.     {
  7.         string N = Console.ReadLine();
  8.  
  9.         int specialSum = 0;
  10.  
  11.         char[] myArr = new char[N.Length - 1];
  12.         if (N[0] == '-')
  13.         {
  14.             for (int i = 0; i < N.Length - 1; i++)
  15.             {
  16.                 myArr[i] = N[i + 1];
  17.             }
  18.             N = new string(myArr);
  19.         }
  20.        
  21.  
  22.         int count = 0;
  23.         int value = 0;
  24.  
  25.         for (int i = N.Length - 1; i >= 0; i--)
  26.         {
  27.             count++;
  28.             value = int.Parse(N[i].ToString());
  29.             if (count % 2 == 1)
  30.             {
  31.                 specialSum += value * (int)Math.Pow(count, 2);
  32.             }
  33.             else
  34.             {
  35.                 specialSum += (int)Math.Pow(value,2) * count;
  36.             }
  37.         }
  38.  
  39.         Console.WriteLine(specialSum);
  40.  
  41.         int lastDigit = 0;
  42.         lastDigit = specialSum % 10;
  43.         int R = specialSum % 26 + 1;
  44.                
  45.         char letter = '\0';
  46.         int next = R - 1;
  47.  
  48.         if (lastDigit == 0)
  49.         {
  50.             Console.WriteLine("{0} has no secret alpha-sequence", N);
  51.         }
  52.         else
  53.         {
  54.             for (int i = 0; i < lastDigit; i++)
  55.             {
  56.                 letter = (char)(65 + next);                
  57.                 Console.Write("{0}", letter);
  58.                 next++;
  59.                 if (letter == 'Z')
  60.                 {
  61.                     next = 0;
  62.                 }
  63.             }
  64.         }
  65.  
  66.         Console.WriteLine();
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement