ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1723. Книга Сандро

The Power of C#
Послано Hikmat Ahmedov 20 фев 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]);
    }
}
Re: The Power of C#
Послано ilalex 23 апр 2013 10:43
Power of Python :)

from collections import Counter
print(Counter(input().strip()).most_common(1)[0][0])
Re: The Power of C#
Послано Maxim 25 янв 2014 22:38
Power of C/C++

int main() {
    //shitcode_fiveloops
}

// AC :)
Re: The Power of C#
Послано BillSu 25 апр 2014 16:29
#include <The Power of me!>
int main()
{
    ThePowerOfMe.makeItAC();
}
...AC!:)

Edited by author 25.04.2014 16:46
Re: The Power of C#
Послано Ilya Breev 12 фев 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#
Послано Raphael 15 сен 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;
}