Advertisement
AlexTasev

ASCII combinations

Apr 10th, 2018
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.61 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _4_CharsSum
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             int num = int.Parse(Console.ReadLine());
  10.  
  11.             int maxSum = 0;
  12.  
  13.             int sumDigits = 0;
  14.             int sumCapsLetters = 0;
  15.             int sumSmallLetters = 0;
  16.             int sumOthers = 0;
  17.  
  18.             string digits = "";
  19.             string capsLetters = "";
  20.             string smallLetters = "";
  21.             string others = "";
  22.  
  23.  
  24.             for (int i = 0; i < num; i++)
  25.             {
  26.                 char currSymbol = char.Parse(Console.ReadLine());
  27.  
  28.                 int currNum = (int)currSymbol;
  29.  
  30.                 if (currSymbol >= '0' && currSymbol <= '9')
  31.                 {
  32.                     digits += currSymbol;
  33.                     sumDigits += currNum;
  34.  
  35.                     if (sumDigits > maxSum)
  36.                     {
  37.                         maxSum = sumDigits;
  38.                     }
  39.  
  40.                 }
  41.                 else if (currSymbol >= 'A' && currSymbol <= 'Z')
  42.                 {
  43.                     capsLetters += currSymbol;
  44.                     sumCapsLetters += currNum;
  45.  
  46.                     if (sumCapsLetters > maxSum)
  47.                     {
  48.                         maxSum = sumCapsLetters;
  49.                     }
  50.                 }
  51.                 else if (currSymbol >= 'a' && currSymbol <= 'z')
  52.                 {
  53.                     smallLetters += currSymbol;
  54.                     sumSmallLetters += currNum;
  55.  
  56.                     if (sumSmallLetters > maxSum)
  57.                     {
  58.                         maxSum = sumSmallLetters;
  59.                     }
  60.                 }
  61.                 else
  62.                 {
  63.                     others += currSymbol;
  64.                     sumOthers += currNum;
  65.  
  66.                     if (sumOthers > maxSum)
  67.                     {
  68.                         maxSum = sumOthers;
  69.                     }
  70.                 }
  71.             }
  72.  
  73.             Console.WriteLine($"Biggest ASCII sum is:{maxSum}");
  74.  
  75.             if (sumDigits == maxSum)
  76.             {
  77.                 Console.WriteLine($"Combination of characters is:{digits}");
  78.             }
  79.             else if (sumCapsLetters == maxSum)
  80.             {
  81.                 Console.WriteLine($"Combination of characters is:{capsLetters}");
  82.             }
  83.             else if (sumSmallLetters == maxSum)
  84.             {
  85.                 Console.WriteLine($"Combination of characters is:{smallLetters}");
  86.             }
  87.             else
  88.             {
  89.                 Console.WriteLine($"Combination of characters is:{others}");
  90.             }
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement