Editorial for CCC '15 J3 - Rövarspråket


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.

by Patrick Au

The problem is asking you to manipulate a string by adding on more characters. Remember to map the consonants to the appropriate vowels.

Time Complexity: \mathcal{O}(N)

Solution — C++

#include <bits/stdc++.h>

using namespace std;

string junior3(string text)
{
    int j;
    string out;
    const string c = "bcdfghjklmnpqrstvwxyzz";
    const string v = "aeiou";
    const vector<string> chars = {"bc", "dfg", "hjkl", "mnpqr", "stvwxyz"};
    for(unsigned i = 0; i < text.size(); ++i)
    {
        out += text[i];
        if(v.find(text[i]) == v.npos)
        {
            for(j = 0; j < 5; ++j)
            {
                if(chars[j].find(text[i]) != chars[j].npos)
                {
                    out += v[j];
                    break;
                }
            }
            out += c[c.find(text[i]) + 1];
        }
    }
    return out;
}

int main()
{
    string s;
    cin >> s;
    cout << junior3(s) << endl;
    return 0;
}

Comments


  • 0
    shuhanzhang  commented on May 13, 2018, 9:53 p.m.

    I don't get this. RIP...