ENG  RUSTimus Online Judge
Online Judge
Online contests
About Online Judge
Frequently asked questions
Site news
Problem set
Submit solution
Judge status
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
back to board

Discussion of Problem 1723. Sandro's Book

The Power of C#
Posted by Hikmat Ahmedov 20 Feb 2013 13:16
In any substring that is encountered the most, at least one letter of that substring should be encountered the same time as the substring.
So, we just need to find the most encountered symbol in the string.
using System;
using System.Linq;

class Program

    static void Main()
        Console.WriteLine((from u in Console.ReadLine().ToArray()
                           group u by u into gg
                           orderby gg.Count() descending
                           select gg.Key).ToList()[0]);
Re: The Power of C#
Posted by ilalex 23 Apr 2013 10:43
Power of Python :)

from collections import Counter
Re: The Power of C#
Posted by Maxim 25 Jan 2014 22:38
Power of C/C++

int main() {

// AC :)
Re: The Power of C#
Posted by BillSu 25 Apr 2014 16:29
#include <The Power of me!>
int main()

Edited by author 25.04.2014 16:46
Re: The Power of C#
Posted by Ilya Breev 12 Feb 2016 20:43
I think that one line could be enough.
Console.WriteLine(input.GroupBy(c => c).OrderByDescending(g => g.Count()).First().Key);
Re: The Power of C#
Posted by Raphael 15 Sep 2022 08:54
// the power of C++ :)
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
    string s;
    cin >> s;

    vector<int> v(30, 0);
    for (int i=0; i<s.size(); ++i) {
    auto c = distance(v.begin(), max_element(v.begin(), v.end()));
    cout << (char)('a'+c);

    return 0;
Re: The Power of C#
Posted by denxxjkee 1 Jun 2024 21:15
Slightly shorter C++ version of Raphael:

#include <algorithm>
#include <cstdio>

int main()
    size_t v[26]{};
    char c;
    while ((c = std::getc(stdin)) != EOF)
        ++v[c - 'a'];
    std::putc(static_cast<char>('a' + std::distance(v, std::max_element(v, v + 26))), stdin);
    return 0;

Edited by author 01.06.2024 21:37