Advertisement
vovanhoangtuan

Bai1

Apr 20th, 2020
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Bai1
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Dictionary<char, int> res = new Dictionary<char, int>();
  11.             string s = Console.ReadLine();
  12.  
  13.             foreach (char value in s)
  14.             {
  15.                 if (value != ' ')
  16.                 {
  17.                     if (res.ContainsKey(value)) res[value]++;
  18.                     else res.Add(value, 1);
  19.                 }
  20.             }
  21.  
  22.             int maxValue = 0;
  23.             int dem = 1;
  24.             char valueCurrent = ' ';
  25.  
  26.             foreach (KeyValuePair<char, int> item in res)
  27.             {
  28.                 if (maxValue < item.Value)
  29.                 {
  30.                     dem = 1;
  31.                     maxValue = item.Value;
  32.                     valueCurrent = item.Key;
  33.                 }
  34.                 else if (maxValue == item.Value) dem++;
  35.             }
  36.  
  37.             if (dem > 1)
  38.             {
  39.                 foreach (KeyValuePair<char, int> item in res)
  40.                 {
  41.                     if (item.Value == maxValue && item.Key - '0' < valueCurrent - '0') valueCurrent = item.Key;
  42.                 }
  43.             }
  44.  
  45.             Console.WriteLine($"{res.Count}\n{valueCurrent}");
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement