fbinnzhivko

02.00 Letters, Symbols, Numbers

May 13th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         int n = int.Parse(Console.ReadLine());
  8.  
  9.         long lettersSum = 0;
  10.         long symbolsSum = 0;
  11.         long numbersSum = 0;
  12.  
  13.         for (int i = 0; i < n; i++)
  14.         {
  15.             string inputLine = Console.ReadLine().ToUpper();   // Convert the input to upper-case
  16.  
  17.             inputLine = Regex.Replace(inputLine, "\\s+", "");
  18.  
  19.             for (int k = 0; k < inputLine.Length; k++)
  20.             {
  21.                 char currentChar = inputLine[k];
  22.                 if (currentChar >= 'A' && currentChar <= 'Z')
  23.                 {
  24.                     // Letters [a-zA-z]
  25.                     lettersSum += (currentChar - 'A' + 1) * 10;
  26.                 }
  27.                 else if (currentChar >= '0' && currentChar <= '9')
  28.                 {
  29.                     // Numbers [0-9]
  30.                     numbersSum += (currentChar - '0') * 20;
  31.                 }
  32.                 else
  33.                 {
  34.                     // Symbols
  35.                     symbolsSum += 200;
  36.                 }
  37.             }
  38.         }
  39.         Console.WriteLine("{0}\n{1}\n{2}",lettersSum,numbersSum,symbolsSum);
  40.     }
  41. }
Add Comment
Please, Sign In to add comment