Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- You are given N strings. Every string consists of letters, symbols, numbers and whitespace. All letters (a-z) and (A-Z) have values corresponding to their position in the English alphabet * 10 (a = 10, A = 10, b = 20, B = 20, …, z = 260, Z = 260). All symbols (like `~!@#$%^&*()_+{}:"|<>?-=[];'\,./) have a fixed value of 200 and all numbers have the value of their digit * 20 (0 = 0, 1 = 20, 2 = 40, 3 = 60, …, 9 = 180). The whitespace is ignored. Your task is to calculate the sum of all letters, all symbols and all numbers from the input and print them, each at a separate line.
- Input
- The input data should be read from the console.
- • At the first line an integer number N is given, specifying the count of the input strings.
- • Each of the next N lines holds an input string.
- The input data will always be valid and in the format described. There is no need to check it explicitly.
- Output
- The output should be printed on the console. It should consist of exactly 3 lines:
- • On the first line print the sum of all letters.
- • On the second line print the sum of all numbers.
- • On the third line print the sum of all symbols.
- using System;
- using System.Text.RegularExpressions;
- class Program
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- long lettersSum = 0;
- long symbolsSum = 0;
- long numbersSum = 0;
- for (int i = 0; i < n; i++)
- {
- string line = Console.ReadLine();
- line = line.ToUpper();
- line = Regex.Replace(line, "\\s+", "");
- for (int k = 0; k < line.Length; k++)
- {
- char currentCar = line[k];
- if (currentCar >= 'A' && currentCar <= 'Z')
- {
- lettersSum += (currentCar - 'A' + 1) * 10;
- }
- else if (currentCar >= '0' && currentCar <= '9')
- {
- numbersSum += (currentCar - '0') * 20;
- }
- else
- {
- symbolsSum += 200;
- }
- }
- }
- Console.WriteLine(lettersSum);
- Console.WriteLine(numbersSum);
- Console.WriteLine(symbolsSum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement