Advertisement
dimipan80

Exam July Morning 2. Letters, Symbols, Numbers

Jul 27th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Threading;
  6.  
  7. public class LettersSymbolsNumbers
  8. {
  9.     private static Dictionary<char, int> alphabet = new Dictionary<char, int>()
  10.     {
  11.         { 'A', 10 }, { 'B', 20 }, { 'C', 30 }, { 'D', 40 }, { 'E', 50 }, { 'F', 60 }, { 'G', 70 },
  12.         { 'H', 80 }, { 'I', 90 }, { 'J', 100 }, { 'K', 110 }, { 'L', 120 }, { 'M', 130 }, { 'N', 140 },
  13.         { 'O', 150 }, { 'P', 160 }, { 'Q', 170 }, { 'R', 180 }, { 'S', 190 }, { 'T', 200 },
  14.         { 'U', 210 }, { 'V', 220 }, { 'W', 230 }, { 'X', 240 }, { 'Y', 250 }, { 'Z', 260 }      
  15.     };
  16.  
  17.     private static char[] whitespaceSymbs = { ' ', '\t', '\r', '\n' };
  18.  
  19.     public static void Main()
  20.     {
  21.         Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
  22.         checked
  23.         {
  24.             int countOfStrings = int.Parse(Console.ReadLine());
  25.  
  26.             int sumOfLetters = 0;
  27.             int sumOfNums = 0;
  28.             int sumOfSymbols = 0;
  29.             if (countOfStrings > 0)
  30.             {
  31.                 for (int i = 0; i < countOfStrings; i++)
  32.                 {
  33.                     string inputString = Console.ReadLine().ToUpper();
  34.                     for (int j = 0; j < inputString.Length; j++)
  35.                     {
  36.                         char current = inputString[j];
  37.                         if (alphabet.ContainsKey(current))
  38.                         {
  39.                             sumOfLetters += alphabet[current];
  40.                         }
  41.                         else if (char.IsDigit(current))
  42.                         {
  43.                             int digit = int.Parse(current.ToString());
  44.                             sumOfNums += digit * 20;
  45.                         }
  46.                         else if (!whitespaceSymbs.Contains(current))
  47.                         {
  48.                             sumOfSymbols += 200;
  49.                         }
  50.                     }
  51.                 }
  52.             }
  53.  
  54.             Console.WriteLine("{0}\n{1}\n{2}", sumOfLetters, sumOfNums, sumOfSymbols);
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement