|
|
back to board/* 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]); } } Power of Python :) from collections import Counter print(Counter(input().strip()).most_common(1)[0][0]) Power of C/C++ int main() { //shitcode_fiveloops } // AC :) #include <The Power of me!> int main() { ThePowerOfMe.makeItAC(); } ...AC!:) Edited by author 25.04.2014 16:46 I think that one line could be enough. Console.WriteLine(input.GroupBy(c => c).OrderByDescending(g => g.Count()).First().Key); // 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; } 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 |
|
|