Advertisement
Filkolev

[Exam Preparation] 02. Letters, Symbols, Numbers

Nov 3rd, 2014
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. using System;
  2.  
  3. class LettersSymbolsNumbers
  4. {
  5.     static void Main()
  6.     {
  7.         int count = int.Parse(Console.ReadLine());
  8.  
  9.         int lettersSum = 0;
  10.         int symbolsSum = 0;
  11.         int digitsSum = 0;
  12.  
  13.         for (int i = 0; i < count; i++)
  14.         {
  15.             string currentString = Console.ReadLine().ToLower();
  16.  
  17.             foreach (var ch in currentString)
  18.             {
  19.                 if (ch == ' ' &&
  20.                     ch != '\t' &&
  21.                     ch != '\r' &&
  22.                     ch != '\n')
  23.                 {
  24.                     if (ch >= 'a' && ch <= 'z')
  25.                     {
  26.                         int weight = (ch - 'a' + 1) * 10;
  27.                         lettersSum += weight;
  28.                     }
  29.  
  30.                     else if (ch >= '0' && ch <= '9')
  31.                     {
  32.                         int weight = (ch - '0') * 20;
  33.                         digitsSum += weight;
  34.                     }
  35.  
  36.                     else
  37.                     {
  38.                         symbolsSum += 200;
  39.                     }
  40.                 }
  41.             }
  42.         }
  43.  
  44.         Console.WriteLine(lettersSum);
  45.         Console.WriteLine(digitsSum);
  46.         Console.WriteLine(symbolsSum);
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement