题目:http://codeforces.com/contest/883/problem/F
思路:判断的时候直接将所有kkk…h变成h就行了
C++代码:
#include <bits/stdc++.h>
using namespace std;
map<string,int> mp;
int main()
{
int n;
cin >> n;
string s,t;
for(int i = 0;i < n;i++)
{
cin >> s;
t = "";
for(int j = 0;j < s.size();j++)
if(s[j] == 'u')
t.push_back('o'),t.push_back('o');
else if(s[j] == 'h')
{
while(t.back() == 'k')
t.pop_back();
t.push_back('h');
}
else
t.push_back(s[j]);
mp[t]++;
}
cout << mp.size() << "\n";
return 0;
}
Python直接用replace:
n = int(input())
ans = []
for i in range(0,n):
s = input()
s = s.replace("u","oo")
while s.count("kh") != 0:
s = s.replace("kh","h")
if not s in ans:
ans.append(s)
print (len(ans))