archangelmihail

SecretsVariant2

Nov 27th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 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 SecretsVariant2
  8. {
  9.     class SecretsVariant2
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string number = Console.ReadLine();
  14.  
  15.             // If theres is '-' (minus) -> programs removes it
  16.             if (number.Contains('-')) number = number.Remove(number.IndexOf('-'), 1);
  17.  
  18.             int sumOfDigits = 0;
  19.  
  20.             for (int i = 0; i < number.Length; i++)
  21.             {
  22.                 int position = number.Length - i;
  23.                 if (position % 2 != 0)
  24.                 {
  25.                     sumOfDigits += (number[i] - 48) * (int)Math.Pow(position, 2);
  26.                 }
  27.                 else
  28.                 {
  29.                     sumOfDigits += (int)Math.Pow(number[i] - 48, 2) * position;
  30.                 }
  31.             }
  32.  
  33.             Console.WriteLine(sumOfDigits);
  34.  
  35.             if (sumOfDigits % 10 == 0)
  36.             {
  37.                 Console.WriteLine("{0} has no secret alpha-sequence", number);
  38.             }
  39.             else
  40.             {
  41.                 for (int i = 0; i < sumOfDigits % 10; i++)
  42.                     Console.Write((char)((sumOfDigits + i) % 26 + 65));
  43.  
  44.                 Console.WriteLine();
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment