Advertisement
Guest User

Excel Columns

a guest
Apr 7th, 2014
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1. using System;
  2.  
  3. class ExcelColumns
  4. {
  5.     static void Main()
  6.     {
  7.         // input
  8.         int n = int.Parse(Console.ReadLine());
  9.         char identifier = new char();
  10.         long result = 0;
  11.         for (int i = n; i > 0; i--)
  12.         {
  13.             identifier = char.Parse(Console.ReadLine());
  14.  
  15.             if (i == 1)
  16.             {
  17.                 result += (long)(identifier - 'A' + 1);
  18.             }
  19.             else
  20.             {
  21.                 result += (long)(identifier - 'A' + 1) * (long)Math.Pow(26, i - 1);
  22.             }
  23.         }
  24.         Console.WriteLine(result);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement