Advertisement
n4wn4w

02. Letters, Symbols, Numbers 25 July 2014 Morning

Mar 18th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int count = int.Parse(Console.ReadLine());
  13.  
  14.             int lettersSum = 0;
  15.             int SymbolsSum = 0;
  16.             int digitsSum = 0;
  17.  
  18.             for (int i = 0; i < count; i++)
  19.             {
  20.                 string currentString = Console.ReadLine().ToLower();  
  21.              //  foreach (var ch in currentString) // tozi string moje da se obhodi i s FOREACH
  22.                 for (int j = 0; j < currentString.Length; j++)
  23.                 {
  24.                     char ch = currentString[j];
  25.  
  26.                    if (ch != ' ' && ch != '\t' && ch != '\r' && ch != '\n')// ako ch e razli4no ot tezi simvoli to da vliza v if i da izvurshva tezi operacii
  27.                    {
  28.                        if (ch >= 'a' && ch <= 'z')
  29.                        {
  30.                            int weight = ((ch - 'a') + 1) * 10;// vadim chara - a i pribavqme 1 zashtoto a = 97 - c= 99 i s epolu4ava 2 a na men mi trqbva da e 3
  31.                            lettersSum += weight;
  32.                        }
  33.                        else if (ch >= '0' && ch <= '9')
  34.                        {
  35.                            int weight = (ch - '0') * 20;// na 0 ne e nujno da pribavqme 1 zashtoto kakto z 'a'- bukvite zashtoto  0 = 48 - 50 = 2 razlikata mi e 2 kolkoto i trqbva da e chisloto
  36.                            digitsSum += weight;
  37.                        }
  38.                        else
  39.                        {
  40.                            SymbolsSum += 200;
  41.                        }
  42.                    }
  43.                 }
  44.             }
  45.             Console.WriteLine(lettersSum);
  46.             Console.WriteLine(digitsSum);
  47.             Console.WriteLine(SymbolsSum);
  48.          }
  49.         }
  50.     }
  51.  
  52.  ////// vtori variant za if else ///////////////
  53.                    /*  if ((ch >= 'a' && ch <= 'z') && (ch != ' ' && ch != '\t' && ch != '\r' && ch != '\n'))
  54.                        {
  55.                            int weight = ((ch - 'a') + 1) * 10;
  56.                            lettersSum += weight;
  57.                        }
  58.                        else if ((ch >= '0' && ch <= '9') && (ch != ' ' && ch != '\t' && ch != '\r' && ch != '\n'))
  59.                        {
  60.                            int weight = (ch - '0') * 20;
  61.                            digitsSum += weight;
  62.                        }
  63.                        else if (ch != ' ' && ch != '\t' && ch != '\r' && ch != '\n')
  64.                        {
  65.                            SymbolsSum += 200;
  66.                        } */
  67.  
  68.  
  69.  
  70.  
  71. ///////////////////// taka go e napravil a4kata po-chisto e
  72.                 int curChar = input[j];
  73.                 if (curChar >= 'A' && input[j] <= 'Z')
  74.                 {
  75.                     curChar = (input[j] - 64) * 10;
  76.                     sumLetters += curChar;
  77.                 }
  78.                 else if (input[j] >= '0' && input[j] <= '9')
  79.                 {
  80.                     curChar = (input[j] - 48) * 20;
  81.                     sumNumbers += curChar;
  82.  
  83.  
  84.  
  85. ///////////////////////////////// 2 reshenie na a4kata //////////////////////////////////
  86.  
  87. int n = int.Parse(Console.ReadLine());
  88.  
  89.         int sumLetters = 0;
  90.         int sumNumbers = 0;
  91.         int sumSymbols = 0;
  92.  
  93.  
  94.         for (int i = 0; i < n; i++)
  95.         {
  96.             string input = Console.ReadLine().ToUpper();
  97.  
  98.             input = Regex.Replace(input, "\\s+", "");
  99.  
  100.             for (int j = 0; j < input.Length; j++)
  101.             {
  102.                 int curChar = input[j];
  103.                 if (curChar >= 'A' && input[j] <= 'Z')
  104.                 {
  105.                     curChar = (input[j] - 64) * 10;
  106.                     sumLetters += curChar;
  107.                 }
  108.                 else if (input[j] >= '0' && input[j] <= '9')
  109.                 {
  110.                     curChar = (input[j] - 48) * 20;
  111.                     sumNumbers += curChar;
  112.                 }
  113.                 else
  114.                 {
  115.                     sumSymbols += 200;
  116.                 }
  117.             }
  118.  
  119.         }
  120.  
  121.         Console.WriteLine(sumLetters);
  122.         Console.WriteLine(sumNumbers);
  123.         Console.WriteLine(sumSymbols);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement