K. Stepan and Vowels

Codeforces
IDCF795K
Time1000ms
Memory256MB
Difficulty
implementationstrings
English · Original
Chinese · Translation
Formal · Original
Stepan likes to repeat vowel letters when he writes words. For example, instead of the word "_pobeda_" he can write "_pobeeeedaaaaa_". Sergey does not like such behavior, so he wants to write a program to format the words written by Stepan. This program must combine all consecutive equal vowels to a single vowel. The vowel letters are "_a_", "_e_", "_i_", "_o_", "_u_" and "_y_". There are exceptions: if letters "_e_" or "_o_" repeat in a row exactly 2 times, like in words "_feet_" and "_foot_", the program must skip them and do not transform in one vowel. For example, the word "_iiiimpleeemeentatiioon_" must be converted to the word "_implemeentatioon_". Sergey is very busy and asks you to help him and write the required program. ## Input The first line contains the integer _n_ (1 ≤ _n_ ≤ 100 000) — the number of letters in the word written by Stepan. The second line contains the string _s_ which has length that equals to _n_ and contains only lowercase English letters — the word written by Stepan. ## Output Print the single string — the word written by Stepan converted according to the rules described in the statement. [samples]
Stepan 在写单词时喜欢重复元音字母。例如,他不会写 "_pobeda_",而是写成 "_pobeeeedaaaaa_"。 Sergey 不喜欢这种行为,因此他想编写一个程序来格式化 Stepan 写的单词。该程序必须将所有连续相同的元音字母合并为一个元音字母。元音字母为 "_a_"、"_e_"、"_i_"、"_o_"、"_u_" 和 "_y_"。 但存在例外:如果字母 "_e_" 或 "_o_" 恰好连续出现 #cf_span[2] 次,例如单词 "_feet_" 和 "_foot_",程序必须跳过它们,不将其合并为一个元音字母。例如,单词 "_iiiimpleeemeentatiioon_" 必须被转换为 "_implemeentatioon_"。 Sergey 非常忙碌,请求你帮助他编写所需的程序。 第一行包含整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 100 000]) —— Stepan 写的单词中的字母数量。 第二行包含字符串 #cf_span[s],其长度等于 #cf_span[n],且仅包含小写英文字母 —— Stepan 写的单词。 请输出一个字符串 —— 根据题述规则转换后的 Stepan 写的单词。 ## Input 第一行包含整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 100 000]) —— Stepan 写的单词中的字母数量。第二行包含字符串 #cf_span[s],其长度等于 #cf_span[n],且仅包含小写英文字母 —— Stepan 写的单词。 ## Output 请输出一个字符串 —— 根据题述规则转换后的 Stepan 写的单词。 [samples]
Let $ s $ be a string of length $ n $, consisting of lowercase English letters. Let $ V = \{a, e, i, o, u, y\} $ be the set of vowels. Define a transformation $ T(s) $ as follows: For each maximal contiguous substring of identical characters $ c^k $ (i.e., $ c $ repeated $ k $ times): - If $ c \notin V $, leave it unchanged: $ c^k \mapsto c^k $. - If $ c \in V $: - If $ c \in \{e, o\} $ and $ k = 2 $, leave it unchanged: $ c^2 \mapsto c^2 $. - Otherwise, replace $ c^k $ with a single $ c $: $ c^k \mapsto c $. Output the resulting string after applying $ T $ to all maximal contiguous vowel runs in $ s $.
Samples
Input #1
13
pobeeeedaaaaa
Output #1
pobeda
Input #2
22
iiiimpleeemeentatiioon
Output #2
implemeentatioon
Input #3
18
aeiouyaaeeiioouuyy
Output #3
aeiouyaeeioouy
Input #4
24
aaaoooiiiuuuyyyeeeggghhh
Output #4
aoiuyeggghhh
API Response (JSON)
{
  "problem": {
    "name": "K. Stepan and Vowels",
    "description": {
      "content": "Stepan likes to repeat vowel letters when he writes words. For example, instead of the word \"_pobeda_\" he can write \"_pobeeeedaaaaa_\". Sergey does not like such behavior, so he wants to write a progr",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF795K"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Stepan likes to repeat vowel letters when he writes words. For example, instead of the word \"_pobeda_\" he can write \"_pobeeeedaaaaa_\".\n\nSergey does not like such behavior, so he wants to write a progr...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Stepan 在写单词时喜欢重复元音字母。例如,他不会写 \"_pobeda_\",而是写成 \"_pobeeeedaaaaa_\"。\n\nSergey 不喜欢这种行为,因此他想编写一个程序来格式化 Stepan 写的单词。该程序必须将所有连续相同的元音字母合并为一个元音字母。元音字母为 \"_a_\"、\"_e_\"、\"_i_\"、\"_o_\"、\"_u_\" 和 \"_y_\"。\n\n但存在例外:如果字母 \"_e_\" 或 \"...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "Let $ s $ be a string of length $ n $, consisting of lowercase English letters.  \nLet $ V = \\{a, e, i, o, u, y\\} $ be the set of vowels.\n\nDefine a transformation $ T(s) $ as follows:\n\nFor each maximal...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments