2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest F. Lost in Transliteration

F. Lost in Transliteration
time limit per test3 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.

For example, the Berland sound u can be written in the Latin alphabet as “u”, and can be written as “oo”. For this reason, two words “ulyana” and “oolyana” denote the same name.

The second ambiguity is about the Berland sound h: one can use both “h” and “kh” to write it. For example, the words “mihail” and “mikhail” denote the same name.

There are n users registered on the Polycarp’s website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?

Formally, we assume that two words denote the same name, if using the replacements “u” “oo” and “h” “kh”, you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.

For example, the following pairs of words denote the same name:

“koouper” and “kuooper”. Making the replacements described above, you can make both words to be equal: “koouper” “kuuper” and “kuooper” “kuuper”.
“khun” and “kkkhoon”. With the replacements described above you can make both words to be equal: “khun” “khoon” and “kkkhoon” “kkhoon” “khoon”.
For a given list of words, find the minimal number of groups where the words in each group denote the same name.

Input
The first line contains integer number n (2 ≤ n ≤ 400) — number of the words in the list.

The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.

Output
Print the minimal number of groups where the words in each group denote the same name.

Examples
input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
output
4
input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
output
5
input
2
alex
alex
output
1
Note
There are four groups of words in the first example. Words in each group denote same name:

“mihail”, “mikhail”
“oolyana”, “ulyana”
“kooooper”, “koouper”
“hoon”, “khun”, “kkkhoon”
There are five groups of words in the second example. Words in each group denote same name:

“hariton”, “kkkhariton”, “khariton”
“hkariton”
“buoi”, “boooi”, “boui”
“bui”
“boi”
In the third example the words are equal, so they denote the same name.

链接:http://codeforces.com/contest/883/problem/F

题意:波兰语中的”h”和”kh”可以互换,”u”和”oo”可以呼唤,给若干个名字,问互不相同的名字有多少个

思路:根据数据范围,暴力将 u 全部转化成 oo ,将 存在的 kh 全部转化成 h

然后塞进set里面,最后输出set的大小。

#include <bits/stdc++.h>
using namespace std;

string check(string s)
{
    string t;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='u')
            t+="oo";
        else if(s[i]=='k')
        {
            int flag=0;
            for(int j=i+1;j<s.length();j++)
            {
                if(s[j]=='k')continue;
                if(s[j]=='h')
                {
                    flag=j;break;
                }
                else break;
            }
            if(flag)
            {
                t+="h";
                i=flag;
            }
            else t+="k";
        }
        else t+=s[i];
    }
    return t;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;cin>>n;
    string s;
    set<string> st;
    while(n--)
    {
        cin>>s;
        s = check(s);
        st.insert(s);
    }
    cout<<st.size()<<endl;

    return 0;
}

转载请注明出处^ ^

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值