Advertisement
tockata

02. Letters, Symbols, Numbers

Jul 25th, 2014
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Program
  6. {
  7.     static void Main()
  8.     {
  9.         int n = int.Parse(Console.ReadLine());
  10.         string input = "";
  11.         string alphabet = " abcdefghijklmnopqrstuvwxyz";
  12.         int lettersSum = 0;
  13.         int numbersSum = 0;
  14.         int symbolsSum = 0;
  15.  
  16.         for (int i = 0; i < n; i++)
  17.         {
  18.             input += Console.ReadLine().ToLower();
  19.         }
  20.         char[] delimiterChars = { ' ', '\t', '\n', '\r' };
  21.         string[] splittedInput = input.Split(delimiterChars);
  22.         string stringToCount = "";
  23.         foreach (string symbol in splittedInput)
  24.         {
  25.             stringToCount += symbol;
  26.         }
  27.  
  28.         for (int i = 0; i < stringToCount.Length; i++)
  29.         {
  30.            
  31.                 int digit = 0;
  32.                 bool checkIsDigit = Int32.TryParse(stringToCount[i].ToString(), out digit);
  33.                 if (alphabet.Contains(stringToCount[i]))
  34.                 {
  35.                     lettersSum += (alphabet.IndexOf(stringToCount[i]) * 10);
  36.                 }
  37.                 else if (checkIsDigit)
  38.                 {
  39.                     numbersSum += (digit * 20);
  40.                 }
  41.                 else
  42.                 {
  43.                     if (stringToCount[i].ToString() != string.Empty)
  44.                     {
  45.                         symbolsSum += 200;
  46.                     }
  47.                 }
  48.            
  49.         }
  50.         Console.WriteLine(lettersSum);
  51.         Console.WriteLine(numbersSum);
  52.         Console.WriteLine(symbolsSum);
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement