Molecules with Potassium X56965


Statement
 

pdf   zip

html

As you may know, potassium has as chemical symbol K; only one other element has a K in its symbol, namely, krypton Kr, a noble gas that hardly ever participates in a molecule.

Your program must process a sequence of molecules, given by their formulas, and none of which contains Kr. Your program should ignore all molecules not containing potassium and, of the rest, it must report the most frequent formula(s) among those coming in the sequence before the first occurrence of NaCl (which is ignored from the counting as it does not have K but, of course, is not ignored as an endmark).

Input

Input is a sequence of molecules. There is no information about whether they are organized in lines nor, if so, how. It is guaranteed that there is at least one occurrence of the molecule NaCl and that, before it, there is at least one occurrence of some molecule containing potassium.

Output

Your program must write the most frequent molecule found in the sequence before the first occurrence of NaCl, under the condition that only molecules including potassium are to be considered. Molecules without potassium are to be ignored, except for the endmarker NaCl. In case of a tie, your program must output all the tied molecules, ordered from smaller ones to larger ones according to Python3’s str ordering. All molecules printed out must be each on a line with no extra spaces or lines.

Public test cases
  • Input

    KCl KI C2H4O2 AsH3 K2S4 K2Te H2O
    K2Te C6H8O6 HK C9H8O4
    K2S4 K2Se HK C8H12N4O3
    KCl KCN CaOH HK H2CO3 H2O NaCl
    FeO SiO BaSO4 CaOH H2O 
    FeS CaH C9H8O4 C8H12N4O3 AsH3 O3 K2S4
    
    
    

    Output

    HK
    
  • Input

    H2O KCN K2Se KCN H2O
    K2Se KCN KCl KCl KCl K2S6 H2O NaCl
    
    

    Output

    KCN
    KCl
    
  • Information
    Author
    José Luis Balcázar
    Language
    English
    Official solutions
    Python
    User solutions
    Python