svetlozar_kirkov

Zerg! (BG Coder)

Oct 11th, 2014
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ConsoleTests
  6. {
  7.     class ConsoleTests
  8.     {
  9.         static void Main()
  10.         {
  11.             Dictionary<string, decimal> dictionary =
  12.                 new Dictionary<string, decimal>();
  13.            
  14.             string[] phrases = new string[]
  15.             {
  16.                 "Rawr","Rrrr","Hsst","Ssst","Grrr","Rarr","Mrrr","Psst","Uaah",
  17.                 "Uaha","Zzzz","Bauu","Djav","Myau","Gruh"
  18.             };
  19.            
  20.             for (int i = 0; i < 15; i++)
  21.             {
  22.                 dictionary.Add(phrases[i],i);
  23.             }
  24.            
  25.             string input = Console.ReadLine();
  26.             List<string> collection = new List<string>();
  27.  
  28.             int chunkSize = 4;
  29.             int stringLength = input.Length;
  30.             for (int i = 0; i < stringLength; i += chunkSize)
  31.             {
  32.                 if (i + chunkSize > stringLength) chunkSize = stringLength - i;
  33.                 collection.Add(input.Substring(i, chunkSize));
  34.  
  35.             }
  36.            
  37.             collection.Reverse();
  38.            
  39.             List<decimal> results = new List<decimal>();
  40.            
  41.             for (decimal i = 0, j = 1; i < collection.Count; i++,j*=15)
  42.             {
  43.                 string temp = collection[Convert.ToInt32(i)];
  44.                 if (dictionary.ContainsKey(temp))
  45.                 {
  46.                     decimal tempDigit = dictionary[temp];
  47.                     results.Add(tempDigit*j);
  48.                 }
  49.             }
  50.  
  51.             Console.WriteLine(results.Sum());
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment