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

Discussion of Problem 1723. Sandro's Book

Hikmat Ahmedov The Power of C# [6] // Problem 1723. Sandro's Book 20 Feb 2013 13:16
/*
ALGORITHM:
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]);
    }
}
ilalex Re: The Power of C# [1] // Problem 1723. Sandro's Book 23 Apr 2013 10:43
Power of Python :)

from collections import Counter
print(Counter(input().strip()).most_common(1)[0][0])
Maxim Re: The Power of C# // Problem 1723. Sandro's Book 25 Jan 2014 22:38
Power of C/C++

int main() {
    //shitcode_fiveloops
}

// AC :)
BillSu Re: The Power of C# // Problem 1723. Sandro's Book 25 Apr 2014 16:29
#include <The Power of me!>
int main()
{
    ThePowerOfMe.makeItAC();
}
...AC!:)

Edited by author 25.04.2014 16:46
Ilya Breev Re: The Power of C# // Problem 1723. Sandro's Book 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);
Raphael Re: The Power of C# [1] // Problem 1723. Sandro's Book 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) {
        ++v[s[i]-'a'];
    }
    auto c = distance(v.begin(), max_element(v.begin(), v.end()));
    cout << (char)('a'+c);

    return 0;
}
denxxjkee Re: The Power of C# // Problem 1723. Sandro's Book 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